P1802 5倍经验日

题目:

Snipaste_2020-06-07_21-00-27.png

正文:

  • 01背包,只是有点变化。
  • 需要注意的是如果剩下的药物不足就要拿到输了的经验,
  • 如果药物充足,也需要用原来的加上输了的经验和原来的加上赢了的经验比较。
  • 以及最后要乘5,且答案要用long long类型。

Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
using namespace std;
#define R read()
#define GC getchar()
#define ll long long
#define ull unsigned long long
#define INF 0x7fffffff
#define LLINF 0x7fffffffffffffff
ll read(){
    ll s=0,f=1;
    char c=GC;
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=GC;}
    while(c>='0'&&c<='9'){s=s*10+c-'0';c=GC;}
    return s*f;
}
int n,x;
int l[1010],w[1010],u[1010];
ll f[1010];
int main(){
    n=R;x=R;//输入
    for(int i=1;i<=n;++i){
        l[i]=R;w[i]=R;u[i]=R;
    }
    for(int i=1;i<=n;++i){//01背包
        for(int j=x;j>=0;--j){
            if(j>=u[i]){//能打赢,判断打之后获得的经验多还是不打之后获得的经验多
                f[j]=max(f[j]+l[i],f[j-u[i]]+w[i]);
            }else{//不能打赢,只能得到输了的经验
                f[j]=f[j]+l[i];
            }
        }
    }
    printf("%lld",f[x]*5);//注意要乘5
    return 0;
}
原文地址:https://www.cnblogs.com/FUXyao/p/13062408.html