| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
【多重部分和】0ms代码贴出
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator