xj2020 @ 2020-04-02 16:24:20
#include<bits/stdc++.h>
using namespace std;
struct thing
{
int price,value,q;
}a[1000];
int n,m;
int imp[61];
int fj[61],wz[61];
int dp[32010];
int main()
{
cin>>n>>m;
int now=m;
for(int i=1;i<=m;i++)
{
cin>>a[i].price>>imp[i]>>a[i].q;
a[i].value=a[i].price*imp[i];
if(a[i].q&&fj[a[i].q]==0)
{
a[i].price+=a[a[i].q].price;
a[i].value+=a[a[i].q].value;
fj[a[i].q]=i;
}
else if(a[i].q&&fj[a[i].q])
{
now++;
a[now].price=a[fj[a[i].q]].price+a[i].price;
a[now].value=a[fj[a[i].q]].value+a[i].value;
a[i].price+=a[a[i].q].price;
a[i].value+=a[a[i].q].value;
}
}
for(int i=1;i<=now;i++)
{
for(int j=n;j>0;j--)
{
if(j>=a[i].value)
dp[j]=max(dp[j],dp[j-
a[i].price]+a[i].value);
}
}
cout<<dp[n];
return 0;
}
我调试了一下,我明明写了a[i].value=a[i].price*imp[i];,但调试时输出的还是价格,没有乘上重要度
by xj2020 @ 2020-04-02 16:26:17
题目
by HearTheWindSing @ 2020-04-02 16:31:36
@xj2020 你在输出后再乘是干啥
by xj2020 @ 2020-04-02 16:33:18
@wangyxhaha 哪里?
by HearTheWindSing @ 2020-04-02 16:41:23
@xj2020
突然发现你就没有输出a[i].value
呀
cin>>a[i].price>>imp[i]>>a[i].q;
by xj2020 @ 2020-04-02 16:43:37
价值=价格×重要度