多重背包及优化
#include <bits/stdc++.h> using namespace std ; const int N=5e5+10; int c[N],S,n,f[N]; int solve(){ int i,j; S=0; memset(f,0,sizeof f); int flag=0; for(i=1;i<=6;i++){ cin>>c[i]; S+=i*c[i]; if(c[i]) flag=1; } if(flag==0) return 0; if(S%2){ cout<<"Can't\n";return 1; } f[0]=1; for(i=1;i<=6;i++){ int t=c[i]; for(int k=1;k<=t;k<<=1){ for(j=S;j>=k*i;j--){ f[j]|=f[j-k*i]; } t-=k; } if(t) for(j=S;j>=t*i;j--) f[j]|=f[j-t*i]; } if(f[S/2]) cout<<"Can"; else cout<<"Can't";cout<<endl; return 1; } signed main(){ while(solve()); }
标签:318,cout,int,大理石,--,flag,acwing From: https://www.cnblogs.com/towboa/p/17138148.html