Hdu 4451 dressing clothes pants shoes simple repulsion

Source: Internet
Author: User

Dressing

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 3735 Accepted Submission (s): 1681

Problem Descriptionwangpeng has N clothes, M pants and K shoes so theoretically he can have nxmxk different combinations o F dressing. One day he wears his pants Nike, shoes adiwang to go to school happily. When he opens the door, his mom asks him to come back and switch the dressing. Mom thinks that Pants-shoes pair is disharmonious because Adiwang is much better than Nike. After being asked to switch again and again Wangpeng figure out all the pairs mom thinks disharmonious. They can is only clothes-pants pairs or pants-shoes pairs. Please calculate the number of different combinations of dressing under Mom ' s restriction.

Inputthere is multiple test cases. For each case, the first line contains 3 integers n,m,k (1≤n,m,k≤1000) indicating the number of clothes, pants and shoes. Second line contains only one integer P (0≤p≤2000000) indicating the number of pairs which mom thinks disharmonious. Next P lines each line would be being one of the "clothes x pants y" or "Pants y shoes z". The first form indicates pair of x-th clothes and y-th pants is disharmonious (1≤x≤n,1≤y≤m), and second form indicates PAI R of y-th pants and z-th shoes is disharmonious (1≤y≤m,1≤z≤k). Input ends with "0 0 0". It is guaranteed, the pairs is different.

Outputfor each case, output the answer on one line.

Sample Input2 2 202 2 21clothes 1 pants 2 22clothes 1 pants 1pants 1 shoes 10 0 0

Sample Output865

Source2012 Asia Jinhua Regional Contest test Instructions: give you n pieces of clothes m trousers K pair of shoes, some of which can not be combined with trousers or trousers and shoes can not be combined, in this case, to find a reasonable combination of units.  
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm > #include <set>using namespace std;typedef long long ll;typedef unsigned long long Ull; #define MM (A, B) memset (A, B , sizeof (a)); const double EPS = 1e-10;const int inf =0x7f7f7f7f;const double pi=acos ( -1); const int Maxn=40000;char s1[20],    S2[20];int X,y,f1[1005],f2[1005];int Main () {int n,m,k,p; while (~SCANF ("%d%d", &n,&m,&k) && (n| | m| |        k) {scanf ("%d", &p); MM (f1,0);        MM (f2,0);        int cnt1=0,cnt2=0;            for (int i=1;i<=p;i++) {scanf ("%s%d%s%d", s1,&x,s2,&y);            if (s1[0]== ' C ') {cnt1++;f1[y]++;}        else {cnt2++;f2[x]++;}        } int res=cnt1*k+n*cnt2;        for (int i=1;i<=m;i++) res-=f1[i]*f2[i];    printf ("%d\n", n*m*k-res); } RETurn 0;} 

Analysis: The comparison of the basis of a tolerance, the title is to seek legal collocation, then we turn to seek illegal collocation, first statistics
The combination of a single pair of clothes and shoes or shoes and trousers makes it easy to find the sum of the corresponding unreasonable collocation numbers, but

There may be a repetition in the middle, because maybe a pair of clothes-pants and trousers-shoes are not compatible, then need to subtract

this repetition , as long as the next pair of trousers by clothes and shoes shared by the number of times good

Hdu 4451 dressing clothes pants shoes simple repulsion

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.