Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

stl 流.........map+vector......- -!

Posted by lvhao945 at 2010-10-14 03:08:22 on Problem 3211
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator