From e47513c310f3690df526f8a8964938bf912c3fad Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Fri, 5 Aug 2016 11:57:21 +0800 Subject: [PATCH] Create 1799.cpp --- QUSTOJ/1799.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 QUSTOJ/1799.cpp diff --git a/QUSTOJ/1799.cpp b/QUSTOJ/1799.cpp new file mode 100644 index 0000000..9394218 --- /dev/null +++ b/QUSTOJ/1799.cpp @@ -0,0 +1,30 @@ +#include +#define MAXN 1010 +int seq[MAXN]; +int seqlen[MAXN]; +int main() +{ + int N; + while(scanf("%d",&N)==1) + { + int i,j,k,max,maxlen=1; + for(i=1; i<=N; i++) + seqlen[i]=1; //seqlen数组存以第i个数为终点的最长上升序列 + for(i=1; i<=N; i++) + scanf("%d",&seq[i]); //seq数组保存序列数组 + for (i=2; i<=N; i++) + { + max=0; + for (j=1; j<=i-1; j++) + { + if(seq[j]max) //在前i-1个序列中,寻找以终点小于seq[i]的最长的子序列,即最优子状态 + max=seqlen[j]; + } + seqlen[i]=max+1; + if(seqlen[i]>maxlen) //seqlen中保存的是第i个数为终点的最长上升序列,找出这个数组中最大的值即为最优序列长度 + maxlen=seqlen[i]; + } + printf("%d\n",maxlen); + } + return 0; +}