• HDU 2159 FATE


    FATE

    Time Limit: 1000ms
    Memory Limit: 32768KB
    This problem will be judged on HDU. Original ID: 2159
    64-bit integer IO format: %I64d      Java class name: Main
     
    最近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

    Source

     
    解题:二维费用完全背包
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <algorithm>
     6 #include <climits>
     7 #include <vector>
     8 #include <queue>
     9 #include <cstdlib>
    10 #include <string>
    11 #include <set>
    12 #include <stack>
    13 #define LL long long
    14 #define pii pair<int,int>
    15 #define INF 0x3f3f3f3f
    16 using namespace std;
    17 const int maxn = 110;
    18 int dp[maxn][maxn],n,m,k,s;
    19 int a[maxn],b[maxn];
    20 int main() {
    21     while(~scanf("%d %d %d %d",&n,&m,&k,&s)) {
    22         for(int i = 1; i <= k; ++i)
    23             scanf("%d %d",a+i,b+i);
    24         memset(dp,0,sizeof(dp));
    25         for(int i = 1; i <= k; ++i) {
    26             for(int j = 1; j <= s; ++j) {
    27                 for(int k = b[i]; k <= m; ++k) {
    28                     dp[k][j] = max(dp[k][j],dp[k-b[i]][j-1]+a[i]);
    29                 }
    30             }
    31         }
    32         if(dp[m][s] < n) puts("-1");
    33         else {
    34             for(int i = 0; i <= m; ++i)
    35                 if(dp[i][s] >= n) {
    36                     printf("%d
    ",m-i);
    37                     break;
    38                 }
    39         }
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    docker容器如何配置hosts文件?
    如何提高LaTeX的编译速度?
    VS编译时提示“无法查找或打开 PDB 文件”的解决方法
    全网最全电子书下载汇总
    chrome谷歌浏览器扩展程序推荐: 一键读图OCR
    关于研究生英文论文写作的一点思考
    小狼毫输入法的详细配置大全
    java的char类型
    Android APP 自动更新实现
    java中double数据失精度(失真)问题处理
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4108019.html
Copyright © 2020-2023  润新知