ZOJ 3741 Eternal Reality

来源:互联网 发布:mac下制作win10启动盘 编辑:程序博客网 时间:2024/04/30 11:01

题目链接:ZOJ 3741 Eternal Reality

dp。

这题我一上来写了一个dfs,然后果然超了。。

总是回避dp。。

看了人家的代码+思路才写出来,这个dp确实不难。。

dp[i][j]表示第i轮比赛,最近一次吃药是第j回合,j=0表示一直没吃药。

注意题目中说了However, no one can achieve this level, even with the help of Level Upper (it has no effect on persons with super powers).所以lv5的时候不管你吃不吃药都干不过lv6的。

#include <iostream>#include <cstring>using namespace std;const int MAX_N = 100 + 10;int dp[MAX_N][MAX_N];int a[MAX_N];int l,n,x,y;int main(){    while(cin >> l >> n >> x >> y)    {        for(int i = 1;i <= n;i++)            cin >> a[i];        memset(dp,0,sizeof(dp));        for(int i = 1;i <= n;i++)        {            for(int j = 0;j <= i;j++)            {                if(j == 0)                {                    dp[i][j] = dp[i - 1][j];                    if(l >= a[i])                        dp[i][j]++;                }                else if(i <= j + x - 1 && i != j)                {                    dp[i][j] = dp[i - 1][j];                    if(l + 1 >= a[i] && a[i] <= 5)                        dp[i][j]++;                }                else if(i > j + x - 1 && i <= j + x + y - 1 && i != j)                {                    dp[i][j] = dp[i - 1][j];                    if(0 >= a[i])                        dp[i][j]++;                }                else if(i == j)                {                    int last = max(0,j - ((i + x + y - 1) - i + 1));                    for(;last >= 0;last--)                        dp[i][j] = max(dp[i - 1][last],dp[i][j]);                    if(l + 1 >= a[i] && a[i] <= 5)                        dp[i][j]++;                }                else                {                    dp[i][j] = dp[i - 1][j];                    if(l >= a[i])                        dp[i][j]++;                }            }        }        int _max = 0;        for(int j = 0;j <= n;j++)            _max = max(dp[n][j],_max);        cout << _max << endl;    }    return 0;}


0 0
原创粉丝点击