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

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

Longest Ordered Subsequence [dp]

2019-11-11 00:55:57
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临沭县| 美姑县| 建瓯市| 册亨县| 吉林市| 讷河市| 若羌县| 昌宁县| 应用必备| 桦南县| 两当县| 德州市| 博白县| 科技| 万山特区| 沅江市| 若羌县| 南涧| 隆林| 开化县| 宁海县| 隆林| 景泰县| 互助| 松潘县| 巧家县| 民权县| 桐庐县| 灵川县| 巨鹿县| 安顺市| 津南区| 大港区| 于都县| 渑池县| 南京市| 商丘市| 永平县| 汽车| 新平| 千阳县|