"HDU 4451 Dressing" water problem, combination number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.