hdu2159——FATE

来源:互联网 发布:python 自动化 工业 编辑:程序博客网 时间:2024/06/05 19:09

FATE

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8296    Accepted Submission(s): 3879


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 101 110 10 1 91 19 10 2 101 12 2
 

Sample Output
0-11
 

Author
Xhd
 

Source
2008信息工程学院集训队——选拔赛
 

Recommend
linle   |   We have carefully selected several similar problems for you:  1203 2955 2844 2571 2084 
 

一道二维费用的完全背包问题

#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int dp[110][110];const int inf = 0x3f3f3f3f;struct node{int w;int c;}guaiwu[110];int main(){int n, m, k, s;while (~scanf("%d%d%d%d", &n, &m, &k, &s)){memset (dp, 0, sizeof(dp));int ans = inf;for (int i = 1; i <= k; ++i){scanf("%d%d", &guaiwu[i].w, &guaiwu[i].c);}for (int i = 1; i <= k; ++i){for (int j = 1; j <= s; ++j){for (int l = guaiwu[i].c; l <= m; ++l){dp[j][l] = max(dp[j][l], dp[j - 1][l - guaiwu[i].c] + guaiwu[i].w);if (dp[j][l] >= n){ans = min(ans, l);}}}}if (dp[s][m] < n){printf("-1\n");continue;}printf("%d\n", m - ans);}return 0;}


0 0
原创粉丝点击