如题,O(n2k) 暴力可过。
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <deque>
#include <queue>
#include <iomanip>
#include <map>
#include <unordered_map>
using namespace std;
#define int long long
#define inf 0x7f7f7f7f
#define maxn 120010
int ca,n,a[maxn],b[7],s[maxn],tot;
bool dp[maxn];
namespace Main{
int rd(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void wrt(int x){
int y=10,len=1;
if(x<0){
x=-x;
putchar('-');
}
while(y<=x){
len++;
y*=10;
}
while(len--){
y/=10;
putchar(x/y+'0');
x%=y;
}
}
void MAIN(){
while(true){
ca++;
bool ed=true;
tot=0;
for(int i=1;i<=6;i++){
cin>>b[i];
if(b[i]!=0){
ed=false;
}
for(int j=1;j<=b[i];j++){
a[++tot]=i;
s[tot]=s[tot-1]+a[tot];
}
}
if(ed){
break;
}
dp[0]=1;
fill(dp+1,dp+s[tot]+1,0);
for(int i=1;i<=tot;i++){
for(int j=a[i];j<=s[i];j++){
dp[j]|=dp[j-a[i]];
}
}
cout<<"Collection #"<<ca<<":\n";
if(s[tot]&1){
cout<<"Can't be divided.\n";
}
else{
if(dp[s[tot]>>1]){
cout<<"Can be divided.\n";
}
else{
cout<<"Can't be divided.\n";
}
}
cout<<'\n';
}
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
Main::MAIN();
return 0;
}