现在的位置: 首页 > 综合 > 正文

Hdu 4451 Dressing (简单容斥)

2014年09月05日 ⁄ 综合 ⁄ 共 618字 ⁄ 字号 评论关闭

题意:有N种衣服,M种裤子和K种鞋子,已知哪些衣服和哪些裤子不能搭配,哪些裤子和哪些鞋子不能搭配,现在要选择一套(衣服+裤子+鞋子),问有多少种搭配方法。

思路:所有的不和谐搭配都是与裤子有关的,所以分别统计对于一条裤子哪些衣服和鞋子不和谐,减掉相应的数量,再加上多减去的,详见代码。

#include <cstdio>
#include <cstring>

int clothes[1005], shoes[1005];

int main ()
{
	int n,m,k;
	while (~scanf("%d%d%d",&n,&m,&k),n||m||k)
	{
		memset(clothes,0,sizeof(clothes));
		memset(shoes,0,sizeof(shoes));
		int cnt;
		scanf("%d",&cnt);
		char s1[10],s2[10];
		int a,b,i;
		while (cnt--)
		{
			scanf("%s%d%s%d",s1,&a,s2,&b);
			if (strcmp(s1, "clothes") == 0)
				clothes[b]++;
			else
				shoes[a]++;
		}
		int ans=n*m*k;
		for (i=1;i<=m;i++)
		{
			ans-=(clothes[i]*k);
			ans-=(shoes[i]*n);
		}
		for (i=1;i<=m;i++)
			ans+=clothes[i]*shoes[i];
		printf("%d\n", ans);
	}
	return 0;
}

抱歉!评论已关闭.