全部评论 7

  • #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int MAXT=1005;
    struct Item{
    ll cost,time,price;
    }a[105];
    ll dp[MAXT];
    int n,TIME,day;
    ll money;

    int main(){
    cin>>n>>TIME>>money>>day;
    for(int i=1;i<=n;i++){
    cin>>a[i].cost>>a[i].time>>a[i].price;
    }
    for(int d=1;d<=day;d++){
    fill(dp,dp+TIME+1,-1e18);
    dp[0]=0;
    vector<int> cnt(n+1,0);
    //多重背包
    for(int i=1;i<=n;i++){
    ll c = a[i].cost;
    ll t = a[i].time;
    ll p = a[i].price;
    if(p <= c) continue; //造了亏钱,跳过
    ll profit = p - c;
    for(int j=TIME;j>=t;j--){
    if(dp[j-t]!=-1e18){
    dp[j]=max(dp[j], dp[j-t]+profit);
    }
    }
    }
    //找当天最大收益以及对应时间
    ll best=0;
    int usedtime=0;
    for(int t=0;t<=TIME;t++){
    if(dp[t]>best){
    best=dp[t];
    usedtime=t;
    }
    }
    money += best;
    // =这里需要回溯cnt数组(可选,复杂)
    /*
    【难点】上面背包代码只算出最大收益,不知道每种装备造几件cnt[i]
    如果要更新第二天价格,背包做完必须回溯,求出cnt数组!
    */
    // 价格更新:用cnt数组更新a[i].price
    for(int i=1;i<=n;i++){
    if(cnt[i]>0){
    a[i].price -= cnt[i];
    }else{
    a[i].price += 1;
    }
    }
    }
    cout<<money<<endl;
    return 0;
    }

    昨天 来自 山东

    1
  • 数据范围???

    2026-08-15 来自 广东

    0
  • ding

    2025-07-29 来自 浙江

    0
  • 家人们,谁懂啊,用虚弱药水和金苹果治疗两个僵尸村民,一个刚好,又被另一个给咬了,最后价格没降,还浪费了宝贵的金苹果和药水

    2025-07-02 来自 浙江

    0
  • ?

    2025-07-01 来自 天津

    0
  • 第四个测试点到底是什么啊,一直RERE

    2025-07-01 来自 上海

    0
  • 我已经在团队里了

    2025-07-01 来自 上海

    0

热门讨论