wustoj2200 一道出错题意的emmm01背包

wustoj2200: 我能反杀

题目:

Time Limit: 5 Sec  Memory Limit: 128 MB   64bit IO Format: %lld
Submitted: 23  Accepted: 7
[Submit][Status][Web Board]

Description

众所周知, cyh喜欢打游戏, 而且喜欢打boss, 但boss的血量太高, cyh必须放技能才打得过boss。 cyh现在有n个技能可以用, 但不同的技能有不同的技能消耗, 有的要消耗血量, 有的会消耗魔法值, 造成的伤害也各不相同, 施放技能需要的时间也不相。 现在cyh的血量不多了, boss的下次攻击就会把cyh打死, 现在告诉你cyh的技能的个数n、 技能消耗、 施法时间t、 技能伤害、 cyh的血量HP、 魔法值MP和boss的血量hp。请你编程来计算cyh能否反杀。

Input

多组输入, 每组输入的第一行包括技能的数量n, cyh的血量HP、 魔法值MP, boss的血量hp以及boss的下次攻击到来的时间t(表示t秒时, 如果cyh没有打死boss, 第t + 1秒, cyh就会被boss打死)。

接下来的n行, 每行4的正整数, 表示技能施法时间, 施放技能的HP消耗、 MP消耗和技能伤害。

(n <=50, 0 <= HP、 MP <= 100, hp <= 1000, 0 <= t <= 100)。

Output

一行输出, 如果cyh能反杀, 数出”YES”, 不能则输出”NO”。

Sample Input 

1 10 10 1000 5
5 5 5 999

Sample Output

NO

思路:

一道没有营养的多维01背包,出题人有问题,把题意出成了完全背包的题意,emmmm。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int N = 107;
const int inf = 0x3f3f3f3f;
int dp[N][N][N];
int main()
{
    int n;
    while(scanf("%d",&n) != EOF){
        int hp,mp,maxn,t,h[N],m[N],ti[N],v[N];
        scanf("%d%d%d%d",&hp,&mp,&maxn,&t);
        for(int i = 0;i < n;++i) scanf("%d%d%d%d",&ti[i],&h[i],&m[i],&v[i]);
        for(int i = 0;i < N;++i)
            for(int j = 0;j < N;++j)
                for(int k = 0;k < N;++k)
                    dp[i][j][k] = 0;
        bool flag = true;
        for(int i = 0;i < n && flag;++i)
            for(int j = hp;j > h[i] && flag;--j)
                for(int k = mp;k >= m[i] && flag;--k)
                    for(int l = t;l >= ti[i];--l){
                        dp[j][k][l] = max(dp[j][k][l],dp[j - h[i]][k - m[i]][l - ti[i]] + v[i]);
                        if(dp[j][k][l] >= maxn){
                            flag = false;
                            break;
                        }
                    }
        printf(flag ? "NO\n" : "YES\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41791981/article/details/82663872