题目
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3741
题目来源:2016.1.25群赛
简要题意:要打人,看Level,可以用技能在后 X ,然后会Level变
0 Y 轮,求最多能打败多少人。
题解
题目还是可以的,但题面非常坑,在表格一长段废话里竟然有句有用的话,如果没看到并不能AC,能力值为 6 的人即便用了技能也无法打败。
状态设置上
dp[i][j] 为进行到第 i 轮战斗,技能进行到j 轮的最多打败多少人。假设 0 为未使用技能的状态
[1,X+Y] 为使用技能的。状态的转移如下:
0,X+Y 可以转移到 0,1
[0,X−1] 转移到自己 +1 此时为技能状态
[X,X+Y−1] 转移到自己 +1 此时为冷却状态增加的时候根据对应的状态下战斗力的大小去判断即可。
要注意需要记录状态的可达性,否则会出错,因为可能导致提前结束然后可以开始下一轮技能。
代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
LL powmod(LL a,LL b, LL MOD) {LL res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// head
const int N = 105;
int a[N];
int dp[N][2*N];
void setMax(int &a, int b) {
a = max(a, b);
}
int main()
{
int l, n, x, y;
while (scanf("%d%d%d%d", &l, &n, &x, &y) == 4) {
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
scanf("%d", a+i);
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
if (dp[i][x+y] != -1) setMax(dp[i][0], dp[i][x+y]);
setMax(dp[i+1][0], dp[i][0] + (l >= a[i+1]));
for (int j = 0; j < x; j++) {
if (dp[i][j] != -1) setMax(dp[i+1][j+1], dp[i][j] + (l+1 >= a[i+1] && a[i+1] != 6));
}
for (int j = 0; j < y; j++) {
if (dp[i][x+j] != -1) setMax(dp[i+1][x+j+1], dp[i][x+j] + (0 >= a[i+1]));
}
}
int ans = 0;
for (int i = 0; i <= x+y; i++) {
setMax(ans, dp[n][i]);
}
printf("%d\n", ans);
}
return 0;
}