QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377965 | #6194. Knapsack Problem | JohnAlfnov | WA | 2ms | 5432kb | C++20 | 1.8kb | 2024-04-05 21:18:22 | 2024-04-05 21:18:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int k;
int c[1145],a[14];
long long f[31][1<<12];
int zt[15];
long long zb[16][4105];
bitset<4096>bs[25];
int suan(){
int zz=0;
for(int i=k-1;i>=0;--i)zz=zz*8+zt[i];
return zz;
}
int sx[105];
int main(){
// freopen("schrodingersbomb.in","r",stdin);
// freopen("schrodingersbomb.out","w",stdout);
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&k);
int as=1;
for(int i=1;i<(1<<k);++i)scanf("%d",&c[i]),as&=(c[i]<=1);
for(int i=0;i<k;++i)scanf("%d",&a[i]);
memset(f,-63,sizeof(f));
f[30][0]=0;
for(int i=29;i>=0;--i){
memset(zb,-63,sizeof(zb));
bs[0].reset();
for(int j=0;j<(1<<(3*k));++j){
if(f[i+1][j]<0)continue;
int jj=j,fl=1;
for(int l=0;l<k;++l){
zt[l]=(jj%8)*2+((a[l]>>i)&1),jj/=8;
if(zt[l]>=8)fl=0;
}
if(!fl)continue;
int su=suan();
zb[0][su]=max(zb[0][su],f[i+1][j]);
bs[0].set(su);
}
int I=1<<i;
for(int z=0;z<k;++z)sx[z]=1<<(k-1);
for(int s=(1<<k);s>=1;--s){
bs[s]=bs[s-1];
for(int i=bs[s-1]._Find_first();i<4096;i=bs[s-1]._Find_next(i)){
int ii=i;
for(int j=0;j<k;++j)zt[j]=ii%8,ii/=8;
int sb=1;
for(int j=0;j<k;++j)if((s>>j)&1){
--zt[j];--sx[j];
if(zt[j]<0||zt[j]-sx[j]>=4)sb=0;
}
zb[s][i]=max(zb[s][i],zb[s-1][i]);
if(sb){
int su=suan();
zb[s][su]=max(zb[s][su],zb[s-1][i]+1ll*c[s]*I);
bs[s][su]=1;
}
}
}
int iz=(1<<k)-1,ri=i;
for(int i=bs[iz]._Find_first();i<4096;i=bs[iz]._Find_next(i)){
int ii=i;
for(int j=0;j<k;++j)zt[j]=ii%8,ii/=8;
int fl=1;
for(int j=0;j<k;++j)if(zt[j]>=4)fl=0;
if(!fl)continue;
f[ri][i]=max(f[ri][i],zb[iz][i]);
}
}
printf("%lld\n",f[0][0]);
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 5432kb
input:
3 2 1 2 4 4 5 3 3226252 19270256 2430652 1187613 12496062 10286165 17494834 24 85 34 4 901133 6693218 13245489 14740234 16186210 11382783 19277321 3855635 16523184 10168517 16195031 971041 10303441 8395899 11618555 529321239 218214127 92942310 207467810
output:
-4485090715960753727 -4485090715960753727 -4485090715960753727
result:
wrong answer 1st numbers differ - expected: '18', found: '-4485090715960753727'