首页 > 其他 > 详细

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

时间:2018-08-05 22:18:57      阅读:213      评论:0      收藏:0      [点我收藏+]

题目: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\n",ans);
    }
}

 

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

原文:https://www.cnblogs.com/Zinn/p/9427407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!