a13518354766 @ 2018-03-22 20:10:19
using namespace std;
int v[60],w[60],mo[60];
int p[60][32000];
bool use[60];
int c[60];
int n,m;
int ans=0;
void dfs(int x,int jia,int ti)
{
if(ans<jia)
{
ans=jia;
}
if(x==m+1)
{
return;
}
if(jia>p[x+1][ti]||jia==0)
{
dfs(x+1,jia,ti);
}
if(mo[x]==0)
{
int u=jia+v[x]*w[x];
if(ti>=v[x]&&u>=p[x+1][ti-v[x]])
{
p[x+1][ti-v[x]]=u;
use[x]=1;
dfs(x+1,u,ti-v[x]);
use[x]=0;
}
return;
}
if(use[mo[x]])
{
int u=jia+v[x]*w[x];
if(ti>=v[x]&&u>=p[x+1][ti-v[x]])
{
p[x+1][ti-v[x]]=u;
dfs(x+1,u,ti-v[x]);
}
return;
}
int u=jia+v[x]*w[x]+v[mo[x]]*w[mo[x]];
if(ti>=v[x]+v[mo[x]]&&u>=p[x+1][ti-v[x]-v[mo[x]]])
{
p[x+1][ti-v[x]-v[mo[x]]]=u;
use[x]=1;
dfs(x+1,u,ti-v[x]-v[mo[x]]);
use[x]=0;
}
}
int main()
{
//freopen("ask.in","r",stdin);
//freopen("ask.out","w",stdout);
int ji=1;
cin>>n>>m;
for(int i=1;i<=m;++i)
{
cin>>v[i]>>w[i]>>mo[i];
}
dfs(1,0,n);
cout<<ans;
return 0;
}
On line 1 column 3, read 100, expected 400. 得分0
by a13518354766 @ 2018-03-23 14:11:22
表沉QAQ