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

求大神看一看啊,为什么会错???

Posted by pojpxa at 2019-03-16 16:00:09 on Problem 1014
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

const int M=20010;
int a[M];
int f[M*10]={0};

int main()
{
	int n,m;
	int ans=0;
	int iii=0;
	while(true)
	{
		memset(f,0,sizeof(f));
		iii++;
		m=0;ans=0;
		for(int i=1; i<=6; i++)
		{
			cin>>n;
			ans=ans+n*i;
			if(n!=0)
				while(n--)
				{
					a[m]=i;
					m++;
				}
		}
		if(m==0)	break;
		if(ans%2==1)
		{
			printf("Collection #%d:\nCan't be divided.\n\n",iii);
			continue;
		}
		m--;
		ans=ans/2;
		f[0]=1;
		for(int i=1; i<=m; i++)
		{
			for(int j=ans; j>=a[i]; j--)
				f[j]=f[j]+f[j-a[i]];
		}
		if(f[ans]>0)	printf("Collection #%d:\nCan be divided.\n\n",iii);
		else	printf("Collection #%d:\nCan't be divided.\n\n",iii);
		
	}
	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