zoukankan      html  css  js  c++  java
  • hdu 2159 二维费用背包

    FATE

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


    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<string.h>
    using namespace std;
    struct node
    {
        int a;
        int b;
    }q[110];
    int main()
    {
        int n,m,k,s,p[110][110],i,j,l;
        while(cin>>n>>m>>k>>s)
        {
            for(i=0;i<k;i++)
                cin>>q[i].a>>q[i].b;
            memset(p,0,sizeof(p));
            for(i=1;i<=m;i++)               //p[i][j]储存容忍度为i,杀第j只怪物的经验
            {
                for(j=1;j<=s;j++)           //j用来控制最多杀k只怪物
                    for(l=0;l<k;l++)
                    if(i>=q[l].b)
                    p[i][j]=max(p[i][j],p[i-q[l].b][j-1]+q[l].a);
                if(p[i][s]>=n)  //一找到经验值大于n,就跳出,因为这时所需容忍度最小
                    break;
            }
            cout<<m-i<<endl;
        }

    }

  • 相关阅读:
    部署 AppGlobalResources 到 SharePoint 2010
    还原一个已删除的网站集
    使用仪表板设计器配置级联筛选器 (SharePoint Server 2010 SP1)
    File or arguments not valid for site template
    Pex and Moles Documentation
    Content Query Webpart匿名访问
    Running Moles using NUnit Console from Visual Studio
    Calling a WCF Service using jQuery in SharePoint the correct way
    Updating Content Types and Site Columns That Were Deployed as a Feature
    asp.net中判断传过来的字符串不为空的代码
  • 原文地址:https://www.cnblogs.com/ainixu1314/p/3376102.html
Copyright © 2011-2022 走看看