HDU 4451 Dressing 2012亚洲区域赛金华现场赛

解题报告:

题目大意:WANGPENG有N件上衣,M件裤子,K双鞋子,且都是不同的,现在输入一些搭配,“clothes x pants y” or “pants y shoes z”.,第一句表示第x件上衣跟第y件裤子搭配是

不合理的,第二句表示第y件裤子与第z双鞋子搭配是不合理的,问一共有多少种合理的搭配方法。

排列组合题,应该以裤子为中心,以为它跟上衣和鞋子都有关系,分别标记裤子不能和那些上衣和鞋子搭配。

 1 #include<cstdio>
 2 #include<cstring>
 3 int cloths[1005],shoes[1005];
 4 int main() {
 5     int N,M,K,P,x,y;
 6     char oper1[20],oper2[20];
 7     while(scanf("%d%d%d",&N,&M,&K)&&(N||M||K)) {
 8         scanf("%d",&P);
 9         memset(cloths,0,sizeof(cloths));
10         memset(shoes,0,sizeof(cloths));
11         int sum=0;
12         while(P--) {
13             scanf("%s%d%s%d",oper1,&x,oper2,&y);
14             if(oper1[0]=='c')
15                 cloths[y]++;
16             if(oper1[0]=='p')
17                 shoes[x]++;
18         }
19         for(int i=1;i<=M;++i)
20         sum+=(N-cloths[i])*(K-shoes[i]);
21         printf("%d\n",sum);
22     }
23     return 0;
24 }
25         
View Code
原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3097491.html