___I_AK_IOI @ 2018-09-10 18:51:17
莫名40分不知道哪里错了,求dalao帮忙
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
#include<list>
#include<stack>
#include<vector>
#include<cstdlib>
#include<map>
#include<iterator>
#include<deque>
using namespace std;
const int MAXN=1e5+7;
const int MAXM=1e3+7;
int w[MAXN][3],v[MAXN][3],F[MAXM][MAXM],tmp[MAXN];
int main()
{
int i,j,tot=0;
int V,P,Q;
int N,m;
cin>>N>>m;
memset(w,0,sizeof(w));
for(i=1;i<=m;i++)
for(j=0;j<=2;j++)
v[i][j]=32001;
for(i=1;i<=m;i++)
{
cin>>V>>P>>Q;
if(Q==0){
w[++tot][0]=P;
v[tot][0]=V;
}
else if(Q>=1)
{
w[Q][++tmp[Q]]=P;
v[Q][tmp[Q]]=V;
}
}
memset(F,0,sizeof(F));
for(i=1;i<=tot;i++)
for(j=N;j>=0;j--)
{
F[i][j]=F[i-1][j];
if(j-v[i][0]>0)
F[i][j]=max(F[i][j],F[i-1][j-v[i][0]]+w[i][0]*v[i][0]);
if(j-v[i][0]-v[i][1]>0)
F[i][j]=max(F[i][j],F[i-1][j-v[i][0]-v[i][1]]+w[i][0]*v[i][0]+w[i][1]*v[i][1]);
if(j-v[i][0]-v[i][2]>0)
F[i][j]=max(F[i][j],F[i-1][j-v[i][0]-v[i][2]]+w[i][0]*v[i][0]+w[i][2]*v[i][2]);
if(j-v[i][0]-v[i][1]-v[i][2]>0)
F[i][j]=max(F[i][j],F[i-1][j-v[i][0]-v[i][1]-v[i][2]]+w[i][0]*v[i][0]+w[i][1]*v[i][1]+w[i][2]*v[i][2]);
}
printf("%d",F[tot][N]);
return 0;
}
by zybnxy @ 2018-09-10 19:10:33
孙语聪大佬tql @白哥小葱
by Evan0911 @ 2018-09-10 19:43:34
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int w[32005],v[32005],n,m,i,j,a[3],t,k,p[32005],b[3];
int mp[65][32005],f[32005];
int main()
{
scanf("%d%d",&m,&n);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&w[i],&v[i],&p[i]);
f[i]=p[i];
v[i]=w[i]*v[i];
}
for(i=1;i<=n;i++)
{
if(p[i]==0)
{
t=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(k=1;k<=n;k++)
{
if(f[k]==i)
{
a[++t]=w[k];
b[t]=v[k];
}
}
for(j=1;j<=m;j++)
{
mp[i][j]=max(mp[i-1][j],mp[i][j]);
if(j>=w[i])
{
mp[i][j]=max(mp[i][j],mp[i-1][j-w[i]]+v[i]);
if(j>=w[i]+a[1])
mp[i][j]=max(mp[i][j],mp[i-1][j-w[i]-a[1]]+v[i]+b[1]);
if(j>=w[i]+a[1]+a[2])
mp[i][j]=max(mp[i][j],mp[i-1][j-w[i]-a[1]-a[2]]+v[i]+b[1]+b[2]);
if(j>=w[i]+a[2])
mp[i][j]=max(mp[i][j],mp[i-1][j-w[i]-a[2]]+v[i]+b[2]);
}
}
}
else
{
for(j=1;j<=m;j++)
{
mp[i][j]=max(mp[i-1][j],mp[i][j]);
}
}
}
printf("%d",mp[n][m]);
}