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 testluck at 2008-12-16 22:17:29 on Problem 1014
#include <stdio.h>
#include <math.h>
#include<iostream>
using namespace std;
long c[120];
long V ;
int f[60000];
int  goon  = 1;

#define max(a,b) (a)>(b)?(a):(b)

void zero(int j)
{	
 	for(int v = V;v >0;v--)
	{
		if(v >= c[j]) f[v] = max(f[v],f[v-c[j]]+c[j]);
		if(f[v] == V) {
			goon = 0;
			break;
		}
	}
}
int main()
{
	int m = 1;
	int k;
	int t ;
	int n[6];
	while(1)
	{
		goon = 1;
		scanf("%d%d%d%d%d%d",&n[0],&n[1],&n[2],&n[3],&n[4],&n[5]);
		 V = (n[0] + n[1]*2 + n[2]*3 + n[3]*4 + n[4]*5 + n[5]*6);
		if(!V)break;	 
		if(V%2) goon = -1;
		else{
		int j = 0;	
		V = V/2;
		memset(f,0,sizeof(f));
		
		for(int i = 0;i < 6 && goon;i++){
			t = log(n[i]*1.0)/log(2.0);
			k = 1;
			if(n[i] > 0) {
				c[j] = i+1;
				zero(j);
				j++;
			}		
		while(goon && k < t){
			c[j] = c[j-1]*2;
			zero(j);
			k++;
			j++;
		}
		
		if(n[i]) c[j] = (i+1)*(n[i]-2*c[j-1]/(i+1)+1);
		if(c[j]){
			zero(j);
			j++;
		}		
		}
		}
		printf("Collection #%d:\n",m);
		if(goon) printf("Can't be divided.\n\n");
		else  printf("Can be divided.\n\n");
		m++;
	}
	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