hdu 4451 Dressing (计数,思维题)

http://acm.hdu.edu.cn/showproblem.php?pid=4451 题意:N clothes, M pants and K shoes,然后给出p个不合法的搭配,形式是“clothes x pants y” or “pants y shoes z”.” 问有多少种合法的方案。 思路:一开始觉得是容斥。。当然可以。。但是实际上,不合法的搭配的形式比较简单,每种不合法的发配都是两个两个的不合法,以及每种不合法的形式都有pants,那么我们就可以通过先确定pants,对于每种pants,方案数就是能和当前pants搭配的clothes数,乘以能和当前pants搭配的shoes数,然后累加每种pants的答案即可。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年03月03日 星期四 20时09分47秒
 4File Name :code/hdu/4451.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=2E6+7;
34int n,m,k;
35int p;
36int a[N];
37int clo[N];
38int sho[N];
39
40int main()
41{
42	#ifndef  ONLINE_JUDGE 
43	freopen("code/in.txt","r",stdin);
44  #endif
45
46	while (~scanf("%d %d %d",&n,&m,&k)&&n&&m&&k)
47	{
48	    ms(clo,0);
49	    ms(sho,0);
50	    LL ans = 0LL;
51	    scanf("%d",&p);
52	    if (p==0)
53	    {
54		ans = 1LL*n*1LL*m*1LL*k;
55		printf("%lld\n",ans);
56		continue;
57	    }
58	    for ( int i = 0 ; i < p ; i++)
59	    {
60		char x[15],y[15];
61		int xid,yid;
62		scanf("%s %d %s %d",x,&xid,y,&yid);
63		if (x[0]=='c') 
64		{
65		    clo[yid]++;
66		}
67		else
68		{
69		    sho[xid]++; 
70		}
71	    }
72
73	    for ( int i = 1; i <= m ; i++)
74	    {
75		ans+=1LL*(n-clo[i])*1LL*(k-sho[i]);
76	    }
77	    printf("%lld\n",ans);
78	}
79
80  #ifndef ONLINE_JUDGE  
81  fclose(stdin);
82  #endif
83    return 0;
84}