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

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

Longest Ordered Subsequence [dp]

2019-11-11 00:22:16
字體:
供稿:網(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ā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 尼木县| 闸北区| 五指山市| 无棣县| 青田县| 柞水县| 鱼台县| 绥宁县| 察雅县| 中阳县| 平南县| 台湾省| 灵山县| 丰台区| 定襄县| 永昌县| 香河县| 玉林市| 博湖县| 荃湾区| 海伦市| 衡山县| 永定县| 略阳县| 纳雍县| 永济市| 玛纳斯县| 美姑县| 出国| 泰兴市| 青冈县| 天祝| 深水埗区| 黎城县| 长泰县| 顺平县| 金山区| 葫芦岛市| 锦屏县| 伽师县| 那坡县|