——悬关
bitset 优化朴素多重背包,提交后满屏挂彩。
代码异常简明:
#include<bits/stdc++.h>
using namespace std;
const int N=120005;
int um[10];
bitset<N> f;
int read(){
int flag=0;
for(int i=1;i<=6;i++) scanf("%d",&um[i]),flag|=um[i];
return flag;
}
int main(){
int T;
while(read()){
printf("Collection #%d:\n",++T);
int x=0;
for(int i=1;i<=6;i++) x+=um[i]*i;
if(x&1){puts("Can't be divided.\n");continue;}
f.reset();f[0]=1;
for(int i=1;i<=6;i++) while(um[i]--) f|=(f<<i);
if(!f[x>>1]) puts("Can't be divided.\n");
else puts("Can be divided.\n");
}
return 0;
}