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 |
stl 流.........map+vector......- -!#include<iostream> #include<map> #include<vector> #include<string> using namespace std; map<string,int> mp; vector<int> vc[10]; string s; int dp[50005]; int main() { int n,m,i,j,k; while(scanf("%d%d",&m,&n)&&m) { mp.clear(); for(i=0;i<m;i++) { cin>>s; mp[s]=i; vc[i].clear(); } for(i=0;i<n;i++) { cin>>j>>s; k=mp[s]; vc[k].push_back(j); } int total=0; for(k=0;k<m;k++) { int sum=0,mx=0; for(i=0;i<vc[k].size();i++)sum+=vc[k][i]; memset(dp,0,sizeof(dp)); dp[0]=1; for(i=0;i<vc[k].size();i++) { for(j=sum/2;j>=vc[k][i];j--) { if(dp[j-vc[k][i]]){ dp[j]=1; if(j>mx)mx=j; } } } total+=sum-mx; } printf("%d\n",total); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator