標籤:acm hdu dp 動態規劃
題意 你去打boss 開始你的藍和血還有boss的血都是100 每秒你先打boss一下 然後boss打你一下你減少q點血 你有n個技能 第i個技能耗藍a[i] 對boss的傷害為b[i] 普攻傷害為1 而且你每秒回複t點藍(恢複後不超過100) 求你最少可以多少次打死boss
你最多能打100/q或者100/q+1次 令d[i][j]表示第i秒所剩藍量為j時boss剩下的最少血量 m為j還未恢複藍之前的藍量 j = min (100, m + t) 那麼有 d[i][j] = min (d[i][j], d[i - 1][m + a[k]] - b[k]);
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N = 105;int a[N], b[N], d[N][N];int main(){ int n, t, q, ans, ti; while (scanf ("%d%d%d", &n, &t, &q), n) { ++n; ti = (100 % q) ? (100 / q + 1) : (100 / q); a[1] = 0, b[1] = 1; for (int i = 2; i <= n; ++i) scanf ("%d%d", &a[i], &b[i]); memset (d, 0x3f, sizeof (d)); d[0][100] = 100; ans = 0; for (int i = 1; i <= ti; ++i) for (int m = 0; m <= 100; ++m) { int j = min (100, m + t); for (int k = 1; k <= n; ++k) if (m + a[k] <= 100) d[i][j] = min (d[i][j], d[i - 1][m + a[k]] - b[k]); if (d[i][j] <= 0) { ans = i, i = ti; break; } } if (ans == 0) printf ("My god\n"); else printf ("%d\n", ans); } return 0;}
Warcraft
Problem DescriptionHave you ever played the Warcraft?It doesn‘t matter whether you have played it !We will give you such an experience.There are so many Heroes in it,but you could only choose one of them.Each Hero has his own skills.When such a Skill is used ,it costs some MagicValue,but hurts the Boss at the same time.Using the skills needs intellegence,one should hurt the enemy to the most when using certain MagicValue.
Now we send you to complete such a duty to kill the Boss(So cool~~).To simplify the problem:you can assume the LifeValue of the monster is 100, your LifeValue is 100,but you have also a 100 MagicValue!You can choose to use the ordinary Attack(which doesn‘t cost MagicValue),or a certain skill(in condition that you own this skill and the MagicValue you have at that time is no less than the skill costs),there is no free lunch so that you should pay certain MagicValue after you use one skill!But we are good enough to offer you a "ResumingCirclet"(with which you can resume the MagicValue each seconds),But you can‘t own more than 100 MagicValue and resuming MagicValue is always after you attack.The Boss is cruel , be careful!
InputThere are several test cases,intergers n ,t and q (0<n<=100,1<=t<=5,q>0) in the first line which mean you own n kinds of skills ,and the "ResumingCirclet" helps you resume t points of MagicValue per second and q is of course the hurt points of LifeValue the Boss attack you each time(we assume when fighting in a second the attack you show is before the Boss).Then n lines follow,each has 2 intergers ai and bi(0<ai,bi<=100).which means using i skill costs you ai MagicValue and costs the Boss bi LifeValue.The last case is n=t=q=0.
OutputOutput an interger min (the minimun time you need to kill the Boss)in one line .But if you die(the LifeValue is no more than 0) ,output "My god"!
Sample Input
4 2 2510 520 1030 2876 704 2 2510 520 1030 2877 700 0 0
Sample Output
4My godHintHint:When fighting,you can only choose one kind of skill or just to use the ordinary attack in the whole second,the ordinary attack costs the Boss 1 points of LifeValue,the Boss can only use ordinary attack which costs a whole second at a time.Good Luck To You!