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

【多重部分和】0ms代码贴出

Posted by fA1sEr at 2015-02-06 19:37:27 on Problem 1014
http://paste.ubuntu.com/10090244/

#include <iostream>
#include <cstring>
using namespace std;
int dp[120000];
int a[] = { 1,2,3,4,5,6 };
int m[6];
int main()
{
	int kase = 1;
	while (1)
	{
		int s = 0;
		for (int i = 0; i < 6; i++){cin >> m[i]; s += m[i]*a[i];}
		if (s == 0)break;
		if (s % 2 == 1) { printf("Collection #%d:\nCan't be divided.\n\n",kase++); continue; }
		memset(dp, -1, sizeof(dp)); dp[0] = 0; s = s / 2;
		for (int i = 0; i < 6; i++)
			for (int j = 0; j <= s; j++)
				if (dp[j] >= 0)dp[j] = m[i];
				else if (j < a[i] || dp[j - a[i]] <= 0)dp[j] = -1;
				else dp[j] = dp[j - a[i]] - 1;
		if(dp[s]>=0) printf("Collection #%d:\nCan be divided.\n\n", kase++);
		else printf("Collection #%d:\nCan't be divided.\n\n", kase++);
	}
	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