真不会起名了 @ 2018-11-04 19:23:16
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct az
{
int v,w,sum;
int fv[10],fw[10];
}a[61];
int total,have,cnt,v[101],w[101],sum[100001];
int main(){
//freopen("1.in","r",stdin);
int n,m,v1;
scanf("%d %d",&have,&total);
for(int z=1;z<=total;++z){
scanf("%d %d %d",&n,&m,&v1);
if(v1==0){
cnt++;
a[cnt].w=n,a[cnt].v=n*m;
}
else{
int q;
a[v1].sum++;q=a[v1].sum;
a[v1].fw[q]=n,a[v1].fv[q]=n*m;
}
}
total=0;
for(int z=1;z<=cnt;++z){
int nw=a[z].w,nv=a[z].v;
total++;
w[total]=nw,v[total]=nv;
if(a[z].sum==1){
total++;
w[total]=nw+a[z].fw[1],v[total]=nv+a[z].fv[1];
}
else if(a[z].sum==2){
total++;
w[total]=nw+a[z].fw[1],v[total]=nv+a[z].fv[1];
total++;
w[total]=nw+a[z].fw[2],v[total]=nv+a[z].fv[2];
total++;
w[total]=nw+a[z].fw[1]+a[z].fw[2],v[total]=nv+a[z].fv[1]+a[z].fv[2];
}
}
/*for(int z=1;z<=total;++z)
cout<<w[z]<<" "<<v[z]<<endl;*/
for(int z=1;z<=total;z++)
for(int x=have;x>=w[z];x--)
if(x>=w[z])
sum[x]=max(sum[x],sum[x-w[z]]+v[z]);
cout<<sum[have];
return 0;
}
by 已注销%Jm9VScx @ 2018-11-04 19:27:12
我指了一下也点了一下