Washing Clothes (POJ 3211)

Source: Internet
Author: User

General test Instructions: There are n pieces of clothing, M color, someone and his female cannon washing clothes, must be a color wash, to wash another color, each dress has time, the person washes all the same, ask for the least.

POJ the evil C + + and g++, I have been ce three times

/*Backpack Ah ... There are so many play do not know is not by the tree-shaped DP dizzy, one up on the set up a three-dimensional array, "f[i][j][0" on behalf of the former I clothes, time difference is J, and the boys wash much of it.  After two hours to find the wrong idea, this will make two backpacks no difference, the answer must be wrong. Positive solution: For each color, do a 01 knapsack tree, add j this volume can fill out, then another backpack volume is sum-j, then Ans=min (Ans,max (j,sum-j))*/#include<cstdio>#include<iostream>#include<cstring>#include<map>#include<vector>#defineN 110#defineM 100010#defineINF 10000010using namespacestd;intF[m],num[n],sum[n],w[n][n],n,m;map<string,int>color;voidinit () { for(intI=1; i<=n;i++)    {        strings; CIN>>s; Color[s]=i; }     for(intI=1; i<=m;i++)    {        intTstrings; scanf ("%d", &t);cin>>s; intC=Color[s]; NUM[C]++; W[C][NUM[C]]=T; SUM[C]+=T; }    inttot=0;  for(intt=1; t<=n; t++)    {        if(!num[t])Continue; Memset (F,0,sizeof(f)); intans=INF; f[0]=1;  for(intI=1; i<=num[t];i++)           for(intj=sum[t];j>=w[t][i];j--) F[j]+=f[j-W[t][i]];  for(intI=0; i<=sum[t];i++)          if(F[i]) ans=min (Max (i,sum[t]-i), ans); Tot+=ans; } printf ("%d\n", tot);}intMain () { while(~SCANF ("%d%d",&n,&m) {memset (num,0,sizeof(num)); memset (SUM,0,sizeof(sum)); Memset (W,0,sizeof(w)); Memset (F,0,sizeof(f)); if(n==0&&m==0) Break;    Init (); }    return 0;}
View Code

Washing Clothes (POJ 3211)

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.