1 条题解
-
1HLBhahaqiu LV 8 MOD @ 2020-08-29 16:37:01
#include<bits/stdc++.h>
using namespace std;
struct node
{
int tot;
int v[5];
int w[5];
}d[61];
long long f[32001];
int n,m;
int main()
{ memset(f,0,sizeof(f));
cin>>n>>m;
for (int i=1;i<=m;i++)
d[i].tot=0;
for (int i=1;i<=m;i++)
for (int j=0;j<=5;j++)
d[i].v[j]=10005;
for (int i=1;i<=m;i++)
{
int a,b,c;
cin>>a>>b>>c;
if (c==0)
d[i].v[0]=a,d[i].w[0]=b*a;
else
d[c].tot++,d[c].v[d[c].tot]=a,d[c].w[d[c].tot]=a*b;
}
for (int i=1;i<=m;i++)
for (int j=n;j>=0;j--)
{
if (j-d[i].v[0]>=0)
f[j]=max(f[j-d[i].v[0]]+d[i].w[0],f[j]);
if (j-d[i].v[1]-d[i].v[0]>=0&&d[i].tot>=1)
f[j]=max(f[j-d[i].v[0]-d[i].v[1]]+d[i].w[0]+d[i].w[1],f[j]);
if (j-d[i].v[2]-d[i].v[0]>=0&&d[i].tot>=2)
f[j]=max(f[j-d[i].v[0]-d[i].v[2]]+d[i].w[0]+d[i].w[2],f[j]);
if (j-d[i].v[1]-d[i].v[0]-d[i].v[2]>=0&&d[i].tot>=2)
f[j]=max(f[j-d[i].v[0]-d[i].v[1]-d[i].v[2]]+d[i].w[0]+d[i].w[1]+d[i].w[2],f[j]);
}
cout<<f[n]<<endl;
return 0;
}
- 1