個人博客鏈接:https://blog.nuoyanli.com/2020/04/03/hdu3308/
題目鏈接
http://acm.hdu.edu.cn/showproblem.php?pid=3308
題意
給定野怪的血量爲,攻擊力爲,你的生命值和魔法值都爲,普通攻擊力爲(不消耗魔法值),使用技能造成的傷害需要消耗魔法值,每你會增加魔法值上限爲(攻擊野怪需要,然後等一秒),問至少幾輪能殺死野怪,不能則輸出.
思路
表示第秒,魔法值爲是對野怪的最大傷害。
感覺就是完全揹包裸題吧…
狀態轉移:
參考代碼
// nuoyanli
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
//#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define kB kush_back
#define FI first
#define SE second
//#define in
#define RI register
#define m_k(a, b) make_kair(a, b)
#define debug(a) cout << "---" << a << "---" << endl
#define debug_(a, b) cout << a << "---" << b << endl
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e5 + 10;
const int M = 1e3 + 10;
const int mod = 2015;
const LL inf = 0x3f3f3f3f;
const double f = 2.32349;
int a[N], b[N], dp[M][M], n, t, q;
void solve() {
IOS;
while (cin >> n >> t >> q && (n + t + q)) {
a[0] = 0;
b[0] = 1;
for (RI int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
int ti = ceil(100.0 / (double)q), ans = 0; //向上取整!!這裏注意
memset(dp, 0, sizeof(dp));
int vis = 0;
for (int i = 1; i <= ti; i++) { //時間
for (int j = 0; j <= 100; j++) {//魔法
int mof = j + t;
if (mof > 100) {
mof = 100;
}
for (int k = 0; k <= n; k++) { //枚舉技能
if (j + a[k] <= 100) { //超過100的狀態是不存在的
dp[i][mof] = max(dp[i][mof], dp[i - 1][j + a[k]] + b[k]); //揹包dp
}
}
if (dp[i][mof] >= 100) { //記錄答案然後跳出
vis = 1;
ans = i;
// debug(i);
break;
}
}
if (vis) {
break;
}
}
if (!vis) {
cout << "My god" << endl;
} else {
cout << ans << endl;
}
}
}
signed main() {
#ifdef in
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
solve();
return 0;
}