_XiAo__ @ 2023-08-26 18:11:18
不知为何对了第1,2,3,10测试点,求大佬调代码。
#include<bits/stdc++.h>
using namespace std;
int n,w[65],w1[65],w2[65],dp[32005],v[65],v1[65],v2[65],dir[65],m,midn;
signed main()
{
cin>>m>>n;
for(int i=1;i<=n;i++)
{
int a,b,c;
cin>>a>>b>>c;
if(c and v1[c])
{
w2[c]=a;
v2[c]=a*b;
}
else if(c)
{
w1[c]=a;
v1[c]=a*b;
}
else
{
midn++;
w[i]=a;
v[i]=a*b;
}
}
for(int i=1;i<=n;i++)
{
for(int j=m;j>=0;j--)
{
if(j-w[i]>=0)dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
if(j-w[i]-w1[i]>=0)dp[j]=max(dp[j],dp[j-w[i]-w1[i]]+v[i]+v1[i]);
if(j-w[i]-w2[i]>=0)dp[j]=max(dp[j],dp[j-w[i]-w2[i]]+v[i]+v1[i]);
if(j-w[i]-w1[i]-w2[i]>=0)dp[j]=max(dp[j],dp[j-w[i]-w1[i]-w2[i]]+v[i]+v1[i]+v2[i]);
}
}
cout<<dp[m];
return 0;
}
by codejiahui @ 2023-08-26 18:43:58
@xiang_ling 不知为何对了???难道是你觉得自己一个都不对吗
by _XiAo__ @ 2023-08-26 19:32:01
@codejiahui 嗯,是啊
by codejiahui @ 2023-08-26 19:34:17
@xiang_ling 那我就帮不了你了
(话说我昨天把表达式求值的op数组char写成int,也能50分
by _XiAo__ @ 2023-08-26 20:57:43
@codejiahui 我就是s13,第三个if的v2写成v1