https://www.nowcoder.com/acm/contest/141/A
拒绝开第五维,通过经状态压缩的path来储存路径。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int maxn = 38;
#define LL long long
int a[38],b[38],c[38],d[38],val[38];
int dp[38][38][38][38];
LL path[38][38][38][38];
int main()
{
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
scanf("%d",&val[i]);
}
int aa,bb,cc,dd;
scanf("%d %d %d %d",&aa,&bb,&cc,&dd);
for(int i=1; i<=n; i++)
for(int q=aa; q>=a[i]; q--)
for(int w=bb;w>=b[i]; w--)
for(int e=cc; e>=c[i]; e--)
for(int r=dd; r>=d[i]; r--)
{
if(dp[q][w][e][r]<dp[q-a[i]][w-b[i]][e-c[i]][r-d[i]]+val[i]){
dp[q][w][e][r]=dp[q-a[i]][w-b[i]][e-c[i]][r-d[i]]+val[i];
path[q][w][e][r]=path[q-a[i]][w-b[i]][e-c[i]][r-d[i]]|(1LL<<(i-1));
}
}
int num=0;
for(int i=0;i<n;i++){
if(path[aa][bb][cc][dd]&(1LL<<i)){
num++;
}
}
printf("%d\n",num);
int p=0;
for(int i=0;i<n;i++){
if(path[aa][bb][cc][dd]&(1LL<<i)){
if(p) printf(" ");
printf("%d",i);
p++;
}
}
printf("\n");
return 0;
}