liuyifan @ 2018-09-05 17:49:49
#include<bits/stdc++.h>
using namespace std;
int v[600000],p[600000],q[600000],f[30000000],n,m;
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&v[i],&p[i],&q[i]);
p[i]*=v[i];
}
for(int i=1;i<=m;i++)if(q[i])p[i]+=p[q[i]],v[i]+=v[q[i]];
for(int i=1;i<=m;i++)
for(int j=n;j>=v[i];j--)if(j>=v[i])f[j]=max(f[j],f[j-v[i]]+p[i]);
cout<<f[n]<<endl;
return 0;
}
by 小水滴 @ 2018-09-05 18:04:32
@liuyifan 请问你主件和附件是怎么判断的?