JZOJ 1003 [ 东莞市选 2007 ] 拦截导弹 —— 递推

Posted zinn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JZOJ 1003 [ 东莞市选 2007 ] 拦截导弹 —— 递推相关的知识,希望对你有一定的参考价值。

题目:https://jzoj.net/senior/#main/show/1003

n^2 的话递推就可以啦。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const maxn=1005;
int n,h[maxn],f[maxn],g[maxn],ans;
int main()
{
    while(1)
    {
        scanf("%d",&n);
        if(!n)return 0;
        memset(f,0,sizeof f);
        memset(g,0,sizeof g);
        for(int i=1;i<=n;i++)scanf("%d",&h[i]);
        f[n]=1; g[n]=1; ans=1;//
        for(int i=n;i;i--)
            for(int j=i+1;j<=n;j++)
            {
                if(h[j]>h[i])f[i]=max(f[i],g[j]+1);
                else if(h[j]<h[i])g[i]=max(g[i],f[j]+1);
                ans=max(ans,g[i]);
            }
        printf("%d
",ans);
    }
}

 

以上是关于JZOJ 1003 [ 东莞市选 2007 ] 拦截导弹 —— 递推的主要内容,如果未能解决你的问题,请参考以下文章