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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Longest Ordered Subsequence [dp]

2019-11-11 00:58:46
字體:
供稿:網(wǎng)友

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;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 介休市| 泊头市| 石嘴山市| 汽车| 滁州市| 嵊州市| 当阳市| 荥阳市| 芮城县| 宜章县| 苍梧县| 惠水县| 滁州市| 鄂尔多斯市| 红安县| 义马市| 高邮市| 昭苏县| 金溪县| 利津县| 贵德县| 宣城市| 黄陵县| 隆尧县| 宜阳县| 龙州县| 绥阳县| 永康市| 磴口县| 呼玛县| 漳浦县| 广宗县| 合川市| 郴州市| 沧州市| 石台县| 河曲县| 南昌县| 自治县| 吐鲁番市| 磐石市|