国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Longest Ordered Subsequence [dp]

2019-11-10 23:59:41
字體:
來源:轉載
供稿:網友

A numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence ( a1, a2, …, aN) be any sequence ( ai1, ai2, …, aiK), where 1 <= i1 < i2 < … < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).

Your PRogram, when given the numeric sequence, must find the length of its longest ordered subsequence.

Input

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000

Output

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

Sample Input

7 1 7 3 5 9 4 8

Sample Output

4

題解

#include<stdio.h>#include<string.h>#define MAX_N 1002int a[MAX_N],dp[MAX_N];int main(){ int N; while(~scanf("%d",&N)){ memset(dp,0,sizeof(dp)); int ans=0; for(int i=0;i<N;i++){ scanf("%d",&a[i]); int MAX_cnt=0; for(int j=0;j<i;j++) if(a[i]>a[j]&&MAX_cnt<dp[j]) MAX_cnt=dp[j]; dp[i]=MAX_cnt+1; if(dp[i]>ans) ans=dp[i]; } printf("%d/n",ans); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永胜县| 尚志市| 高青县| 河源市| 阳西县| 禹城市| 汉阴县| 丹巴县| 伊通| 湟源县| 蒙自县| 克东县| 襄城县| 丰宁| 兰考县| 蒙山县| 敖汉旗| 万州区| 金昌市| 泾阳县| 丹巴县| 云阳县| 玉林市| 雅安市| 偃师市| 永年县| 忻城县| 扎鲁特旗| 尚志市| 新龙县| 仙游县| 探索| 灵宝市| 道孚县| 玛曲县| 陈巴尔虎旗| 韩城市| 内乡县| 缙云县| 开原市| 元氏县|