poj2533(DP)(与杭电1257一模一…
来源:互联网 发布:手机怎样看淘宝的积分 编辑:程序博客网 时间:2024/05/01 06:49
Longest Ordered Subsequence
Time Limit: 2000MSMemory Limit: 65536KTotal Submissions: 22202Accepted: 9565
Description
A numeric sequence ofai is ordered if a1< a2 < ...< aN. Let the subsequence of thegiven 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 manyothers. All longest ordered subsequences are of length 4, e. g.,(1, 3, 5, 8).
Your program, when given the numeric sequence, must find the lengthof its longest ordered subsequence.
Your program, when given the numeric sequence, must find the lengthof its longest ordered subsequence.
Input
The first line of input file containsthe length of sequence N. The second line contains the elements ofsequence - N integers in the range from 0 to 10000 each, separatedby spaces. 1 <= N <= 1000
Output
Output file must contain a singleinteger - the length of the longest ordered subsequence of thegiven sequence.
Sample Input
71 7 3 5 9 4 8
Sample Output
4
Source
Northeastern Europe 2002, Far-Eastern Subregion
这个代码就是杭电1257最少拦截系的 代码。。一点都没有改过。。
#include<stdio.h>
int a[10010],b[10010];
int main()
{
int i,j,n,max;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);//输入数据
b[0]=1;//初始化,以a[0]结尾的最长递增子序列长度为1
for(i=1;i<n;i++)//i从0开始和从1开始关系不大(是一样的)
{
b[i]=1;//b[i]最小值为1
for(j=0;j<i;j++)//从j到i进行比较(j<i哦)
if(a[i]>a[j]&&b[j]+1>b[i])//记得这边b[j]+1>b[i]不能少,我试了。
b[i]+=1;
}
for(max=i=0;i<n;i++)//求出整个序列的最长递增子序列的长度
if(b[i]>max)
max=b[i];
printf("%d\n",max);
}
return 0;
}
int a[10010],b[10010];
int main()
{
}
- poj2533(DP)(与杭电1257一模一…
- 杭电1257(DP)
- poj2533 简单DP LIS
- ACM POJ2533 简单dp
- POJ2533/hdoj1950【DP】
- poj2533--Longest Ordered Subsequence(dp:最长上升子序列)
- 杭电2571(DP)。
- POJ2533-Longest Ordered Subsequence(dp)
- 杭电1257(最少拦截系统)dp方法
- poj2533
- POJ2533
- poj2533
- poj2533
- poj2533
- POJ2533
- poj2533
- POJ2533
- poj2533
- (DP)最大子段和问题分析和总结(…
- poj1050(DP)
- poj1159(回文字串)
- (挑战编程_7_1)Light, more light
- poj1163(DP)and3176(DP)多串的…
- poj2533(DP)(与杭电1257一模一…
- jq-手机-图片大小
- 木兰花令——纳兰性德
- HDOJ2602(DP0-1背包)
- poj1742andHDOJ2844(DP多重背包)
- poj1276(DP多重背包)
- 真语
- poj1083
- 屌丝程序员日常工作中的一些问题