There are clothes, trousers, shoes, respectively, n,m,k, give p to the discordant clothing-pants or pants-shoes collocation, ask how many kinds of harmonious underwear shoes collocation.
All the combinations have cn1cm1ck1 species.
Set P pair in the P1-pants, p2 pair of trousers-shoes, the discordant collocation of a total of p1*ck1+p2*cn1 species, but there are repeated calculations two times with a total of P3 pair, they quoted the same trousers. The trousers I are quoted in P1 Li Times, and RI times are referenced in P2, then P3=∑ (1*CLI1CRI1). So the answer is N*M*K-P1*K-P2*N+P3.
1#include <cstdio>2#include <cstring>3#include <Set>4 using namespacestd;5 6 intn,m,k;7typedef pair<int,int>P;8P pants[1005];//I Pant was quoted first by P1, and was P2 quoted second times.9 intp,p1,p2,p3;Ten intans; One A intMain () - { -Freopen ("4451.txt","R", stdin); the while(SCANF ("%d%d%d", &n,&m,&k)! =EOF) - { - if(n==0&&m==0&&k==0) Break; -ans=n*m*K; +memset (Pants,0,sizeof(pants)); -p1=p2=p3=0; +scanf"%d",&p); A Chars1[Ten],s2[Ten]; at intn1,n2; - for(intI=0; i<p;i++) - { -scanf"%s", S1); -scanf"%d",&N1); -scanf"%s", S2); inscanf"%d",&n2); - if(s1[0]=='C') to { +p1++; -pants[n2].first++; the}Else if(s1[0]=='P') * { $p2++;Panax Notoginsengpants[n1].second++; - } the } + for(intI=1; i<=m;i++) A { thep3+=pants[i].first*Pants[i].second; + } -ans-=p1*k+p2*n-P3; $printf"%d\n", ans); $ } - return 0; -}
"HDU 4451 Dressing" water problem, combination number