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

Who can tell me the reason??? Why RE???????

Posted by y08dhx at 2009-05-28 00:01:34 on Problem 3211
#include<iostream>
#include<string.h>
using namespace std;
char color[120][12];
int data[120][105];
int loc[120];
int sum[120];
int cap[110][110*1000];
int ncolor,ncase;
//***************************************************
int max(int a,int b)
{
	return a>b?a:b;
}
//*************************************************************
int solve(int x)
{
	int c=sum[x]/2;
	int index=loc[x];
	for(int i=0;i<=c;++i)
		cap[0][i]=0;
	for(int i=0;i<=index;++i)
		cap[i][0]=0;

//	memset(cap,0,sizeof(cap));
	for(int i=1;i<=index;++i)
	{
		for(int j=1;j<=c;++j)
		{
			cap[i][j]=cap[i-1][j];
			if(j>=data[x][i])
			{
				cap[i][j]=max(cap[i][j],cap[i-1][j-data[x][i]]+data[x][i]);
			}
		}
	}
	return sum[x]-cap[index][c];
}
int main()
{
	int temp;
	char str[20];
	while(scanf("%d%d",&ncolor,&ncase),ncase)
	{
		//cin>>ncolor>>ncase;
	//	scanf("%d%d",&ncolor,&ncase);
	//	if(ncolor==0 && ncase==0)
	//		break;
		memset(loc,0,12);
		memset(sum,0,12);
		memset(data,0,sizeof(data));
		for(int i=0;i<ncolor;++i)
			scanf("%s",color[i]);
		for(int i=0;i<ncase;++i)
		{
			scanf("%d %s",&temp,str);
			for(int j=0;j<ncolor;++j)
			{
				if(strcmp(str,color[j])==0)
				{
					loc[j]++;
					data[j][loc[j]]=temp;
					sum[j]+=temp;
					break;
				}
			}
		}
		int ans=0;
		for( int i=0;i<ncolor;++i)
		{
			if(loc[i]>0)
				ans+=solve(i);
		}
		//cout<<ans<<endl;
		printf("%d\n",ans);
	}
	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