标签:include std ons -- get clu algorithm 东莞市 target
题目: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 ] 拦截导弹 —— 递推
标签:include std ons -- get clu algorithm 东莞市 target
原文地址:https://www.cnblogs.com/Zinn/p/9427407.html