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

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

Longest Ordered Subsequence [dp]

2019-11-11 02:13:24
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(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;}
上一篇:瘋狂的采藥-洛谷 1616

下一篇:生理周期

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 松桃| 类乌齐县| 根河市| 青川县| 巴里| 吉林市| 阿克| 永新县| 德格县| 晋城| 开原市| 丹东市| 固阳县| 正蓝旗| 兴安盟| 冷水江市| 广东省| 屏东市| 湖北省| 安图县| 三江| 嘉定区| 来宾市| 如东县| 洛隆县| 手游| 通榆县| 鹤岗市| 泰兴市| 荃湾区| 镇康县| 师宗县| 龙陵县| 襄樊市| 开封市| 西盟| 凤城市| 舞阳县| 会宁县| 余姚市| 松江区|