题意:
现在有N种衣服..M种裤子和K种鞋子..现在告诉哪些衣服和哪些裤子不能搭配..哪些裤子和哪些鞋子不能搭配..现在要选择一套(衣服+裤子+鞋子)..问有多少种搭配方法...
题解:
注意的是..冲突的里面都包括裤子...所以只要统计对于一个裤子有多少个冲突的衣服..和冲突的鞋子.相乘就是多减去的搭配方案了...
Program:
#include<iostream> #include<stack> #include<queue> #include<stdio.h> #include<algorithm> #include<string.h> #include<cmath> #define ll long long #define oo 1000000007 #define eps 1e-5 #define MAXN 1005 #define MAXM 3000005 using namespace std; char s[105]; int num[MAXN][2]; int main() { int N,M,K,P,i,t1,t2,x1,x2,ans; while (~scanf("%d%d%d",&N,&M,&K) && N) { ans=M*N*K; memset(num,0,sizeof(num)); scanf("%d",&P); while (P--) { scanf("%s%d",s,&x1); if (s[0]=='c') t1=0; if (s[0]=='p') t1=1; if (s[0]=='s') t1=2; scanf("%s%d",s,&x2); if (s[0]=='c') t2=0; if (s[0]=='p') t2=1; if (s[0]=='s') t2=2; if (t1==1) { ans-=N; num[x1][0]++; }else { ans-=K; num[x2][1]++; } } for (i=1;i<=M;i++) ans+=num[i][0]*num[i][1]; printf("%d\n",ans); } return 0; }