首页 > 其他分享 >HDU 2159 FATE

HDU 2159 FATE

时间:2022-10-25 17:06:51浏览次数:74  
标签:10 HDU FATE xhd int min 忍耐 include 2159


题目链接:​​传送门​​ 题面:


FATE

Problem Description

最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级。现在的问题是,xhd升掉最后一级还需n的经验值,xhd还留有m的忍耐度,每杀一个怪xhd会得到相应的经验,并减掉相应的忍耐度。当忍耐度降到0或者0以下时,xhd就不会玩这游戏。xhd还说了他最多只杀s只怪。请问他能升掉这最后一级吗?

Input

输入数据有多组,对于每组数据第一行输入n,m,k,s(0 < n,m,k,s < 100)四个正整数。分别表示还需的经验值,保留的忍耐度,怪的种数和最多的杀怪数。接下来输入k行数据。每行数据输入两个正整数a,b(0 < a,b < 20);分别表示杀掉一只这种怪xhd会得到的经验值和会减掉的忍耐度。(每种怪都有无数个)

Output

输出升完这级还能保留的最大忍耐度,如果无法升完这级输出-1。

Sample Input

10 10 1 10
1 1
10 10 1 9
1 1
9 10 2 10
1 1
2 2

Sample Output

0
-1
1

很明显的二维费用背包
一维是忍耐度
一维是怪
一层枚举怪
另外两层枚举忍耐度和杀多少只怪就好了
如果过程中已经升级就直接记录答案

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
int f[B][B], a[B], b[B];
int n, v, k, s, w;

int main() {
while (scanf("%d%d%d%d", &w, &v, &n, &s) != EOF)
{
int min = 1000000;
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
for (int i = 1; i <= n; i++)
for (int j = b[i]; j <= v; j++)
for (int k = 1; k <= s; k++)
{
f[j][k] = max(f[j][k], f[j - b[i]][k - 1] + a[i]);
if (f[j][k] >= w and j < min) min = j;
}
if (min != 1000000) printf("%d\n", v - min);
else puts("-1");
}
}


标签:10,HDU,FATE,xhd,int,min,忍耐,include,2159
From: https://blog.51cto.com/lyle/5794947

相关文章

  • HDU 3466 Pround Merchants
    题目链接:​​传送门​​题面:ProudMerchantsProblemDescriptionRecently,iSeawenttoanancientcountry.Forsuchalongtime,itwasthemostwealthyandpow......
  • HDU 1171 Big Event In HDU
    题目链接:​​传送门​​BigEventinHDUProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’t......
  • HDU 3535 AreYouBusy
    题目链接:​​传送门​​题面:AreYouBusyProblemDescriptionHappyNewTerm!Ashavingbecomeajunior,xiaoArecognizesthatthereisnotmuchtimeforhertoAC......
  • HDU 2844 Coins
    题目链接:​​传送门​​​题面:ProblemDescriptionWhuacmersusecoins.TheyhavecoinsofvalueA1,A2,A3…AnSilverlanddollar.OnedayHibixopenedpurseandfoun......
  • HDU 1203 I NEED A OFFER!
    题目链接:​​传送门​​题面:INEEDAOFFER!ProblemDescriptionSpeakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了......
  • HDU 1114 Piggy-Bank
    题目链接:​​传送门​​Piggy-BankProblemDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Them......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......
  • HDU 2602 Bone Collector
    题目链接:​​传送门​​​题面:ProblemDescriptionManyyearsago,inTeddy’shometowntherewasamanwhowascalled“BoneCollector”.Thismanliketocollec......
  • HDU2376 Average distance
    题目链接:传送门求树上任意两点间的路径和的平均值非常套路统计每条边被经过多少次就是两边的点数的乘积注意精度就好#include<cstdio>#include<cstring>#include<alg......
  • HDU 1394 Minimum Inversion Number
    题目链接:​​传送门​​求出原数组的逆序对算把一个数从对头拿到队尾的过程中产生的贡献诶我好像昨天做过这个题#include<iostream>#include<cstdio>#include<cstring......