Poj 3211 logging clothes

Source: Internet
Author: User
Tags cmath

I can only say that the question is heartless. During the competition, we can see that the game is just as divided into two parts: 01 backpack, however, the WS string profoundly exposes the C language skills of my scum and has to be written using map. There is a small point in the result that cannot be processed... The final teammate couldn't see it. He put down the formula he was pushing and went up with the string two Wa and then Ac...

My AC code:

# Include <iostream> # include <stdio. h> # include <string> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # include <map> # define n 2222 using namespace STD; map <string, int> MP; int sum [N]; int num [N]; int DP [N]; int f [15] [N]; int main () {int M, N; char STR [N]; while (~ Scanf ("% d", & M, & N) {If (m + n = 0) break; memset (Num, 0, sizeof num ); memset (sum, 0, sizeof sum); memset (DP, 0, sizeof DP); int time; memset (F, 0, sizeof F); For (INT I = 1; I <= m; I ++) {scanf ("% s", STR); MP [STR] = I; // Save the numbered array} For (INT I = 1; I <= N; I ++) {scanf ("% d % s", & time, STR ); // cout <MP [STR] <Endl; sum [MP [STR] + = time; // record the total time of a certain color num [MP [STR] ++; // record the total number of parts of a certain color f [MP [STR] [num [MP [STR] = time; // J dress} int ans = 0; For (INT I = 1; I <= m; I ++) numbered MP [STR) {int v = (sum [I] + 1)/2; for (Int J = 1; j <= num [I]; j ++) for (int K = V; k> = f [I] [J]; k --) {DP [k] = max (DP [K], DP [k-f [I] [J] + F [I] [J]);} ans + = max (DP [v], sum [I]-DP [v]); memset (DP, 0, sizeof DP); // you forgot to clear it, wa several times} printf ("% d \ n", ANS);} return 0 ;} /* 2 6 blue red2 red8 red3 blue5 red4 blue6 red3 7 blue red yy2 red8 red3 blue5 red4 blue6 red3 yy3 4red blue yellow2 red3 blue4 blue6 red0 0 */

Code of teammates:

#include <iostream>#include<stdio.h>#include<string>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<map>#define N 22220using namespace std;struct Node{    int t;    string str;}node[N];int dp[N];int cmp(Node a,Node b){    return a.str>b.str;}int main(){    int m,n,i,j;    char c[20];    while(~scanf("%d%d",&m,&n))    {        if(n+m==0) break;        for(int i=0;i<m;i++)           scanf("%s",c);        for(int i=0;i<n;i++)        {            scanf("%d",&node[i].t);            cin>>node[i].str;        }        sort(node,node+n,cmp);        int k=0;        int a[N],sum;        int ans=0;        for(i=0;i<n;)        {           for(j=i;j<n;j++)                if(node[j].str!=node[j+1].str)                    break;            k=0;sum=0;           for(i;i<=j&&i<n;i++)           {               a[k++]=node[i].t;               sum+=node[i].t;           }            memset(dp,0,sizeof(dp));            int va=sum/2;            for(int te=0;te<k;te++)                for(int v=va;v>=a[te];v--)                  dp[v]=max(dp[v-a[te]]+a[te],dp[v]);            ans+=max(dp[va],sum-dp[va]);        }        printf("%d\n",ans);    }    return 0;}


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.