Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大牛们,帮忙改一下程序,实在找不出来哪里错了,老是 RE !#include<stdio.h> #include<string.h> #include<math.h> const int N=100005; int m,n,cloth[10][105],t,c[15]; char col[12][15], ch[15]; int hh[N]; int min(int *a, int n){ memset(hh, 0, sizeof(hh)); int sum=0, mn=1234567,tag=0,i,j; for( i=0; i<n; i++){ sum+=a[i]; tag++; if(hh[a[i]]==0) hh[a[i]]=tag; for( j=0; j<=sum; j++) if(hh[j] && hh[j]!=tag && hh[a[i]+j]==0) hh[a[i]+j]=tag; } for(i=0; i<=sum/2; i++) if(hh[i] && mn > sum-2*i) mn = sum-2*i; return (mn+sum)/2; } int main(){ while(scanf("%d%d",&m,&n),m||n){ int i,j; memset(c, 0, sizeof(c)); for(i=0; i<m; i++) scanf("%s", col[i]); for(i=0; i<n; i++){ scanf("%d%s",&t, ch); for(j=0; j<m; j++) if(strcmp(ch, col[j])==0) cloth[j][c[j]++] = t; } int sum=0; for(i=0; i<n; i++) if(c[i]) sum+=min(cloth[i],c[i]); printf("%d\n", sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator