很简单的一个题,只是我最近很少自己写出来过题。自己写出了个dp题很爽,所以写篇博客。
就贴个代码算了,明天还有大事
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<deque>
#include<map>
#include<stdlib.h>
#include<set>
#include<iomanip>
#include<stack>
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x & -x
#define fi first
#define se second
#define endl "\n"
#define bug cout<<"----acac----"<<endl
#define IOS ios::sync_with_stdio(false), cin.tie(0),cout.tie(0)
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 1.5e5+50;
const double eps = 1e-7;
const double inf = 0x3f3f3f3f;
const double lnf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
const double pi=3.141592653589;
int a[8],b[maxn],dp[maxn];
int main()
{
int cas=1;
while(1)
{
int sum=0;
for(int i=1;i<=6;i++)
{
scanf("%d",&a[i]);
sum+=i*a[i];
}
if(sum==0)break;
int cnt=0;
if(sum%2==1)
{
printf("Collection #%d:\n",cas++);
printf("Can't be divided.\n\n");
continue;
}
for(int i=1;i<=6;i++)
{
for(int j=1;j<=a[i];j<<=1)
{
b[++cnt]=j*i;
a[i]-=j;
}
if(a[i])
{
b[++cnt]=a[i]*i;
a[i]=0;
}
}
ms(dp,0);
dp[0]=1;
for(int i=1;i<=cnt;i++)
{
// printf("%d\n",b[i]);
for(int j=sum;j>=b[i];j--)
{
if(dp[j-b[i]])
{
dp[j]=1;
}
}
}
if(dp[sum/2])
{
printf("Collection #%d:\n",cas++);
printf("Can be divided.\n\n");
}
else
{
printf("Collection #%d:\n",cas++);
printf("Can't be divided.\n\n");
}
}
return 0;
}