本文主要是介绍HDU 2159 2018-1-29,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FATE
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 16453 Accepted Submission(s): 7726
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 <cstdio>
# include <cstdlib>
# include <cmath>
# include <cstring>
# include <string>
# include <iostream>
# include <iomanip>
# include <algorithm>
# include <stack>
# include <vector>
# include <queue>
using namespace std;using namespace std;
int main()
{int n, m, k, s;int a[102], b[102];int dp[102][102];while (cin >> n >> m >> k >> s) {memset(dp, 0, sizeof(dp));for (int i = 0; i<k; i++) {cin >> a[i] >> b[i];}int tem = 10000007;for (int i = 0; i<k; i++) {for (int j = b[i]; j <= m; j++) {for (int h = 1; h <= s; h++) {dp[j][h] = max(dp[j][h], dp[j - b[i]][h - 1] + a[i]);if (dp[j][h] >= n)tem = min(tem, j);}}}if (tem == 10000007) cout << "-1\n";else cout << m - tem << endl;}return 0;
}
这篇关于HDU 2159 2018-1-29的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!