1 条题解

  • 0
    @ 2026-10-2 2:21:46

    用收服数量和消耗精灵球数保存最少伤害,伤害必须严格小于初始体力,零伤害无需扣除体力。

    #include <bits/stdc++.h>
    using namespace std;
    int main(){int balls,hp,n;cin>>balls>>hp>>n;const int INF=1000000000;vector<vector<int>>d(n+1,vector<int>(balls+1,INF));d[0][0]=0;int processed=0;while(n--){int b,w;cin>>b>>w;processed++;for(int count=processed;count>=1;count--)for(int j=balls;j>=b;j--)d[count][j]=min(d[count][j],d[count-1][j-b]+w);}int count=processed;while(count&&*min_element(d[count].begin(),d[count].end())>=hp)count--;int damage=*min_element(d[count].begin(),d[count].end());cout<<count<<' '<<hp-damage<<"\n";}
    
    • 1

    信息

    ID
    3967
    时间
    1000ms
    内存
    128MiB
    难度
    4
    标签
    递交数
    0
    已通过
    0
    上传者