POJ 2533 动态规划入门 (LIS)
Longest Ordered Subsequence
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 42914 Accepted: 18914
Description
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
一个裸的 LIS
直接给状态转移方程: if (a[j]>a[i]) f[j]=max(f[j],f[i]+1);
#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[1005],f[1005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
if(a[j]>a[i]) f[j]=max(f[i]+1,f[j]);
for(int i=1;i<=n;i++)
f[0]=max(f[0],f[i]);
printf("%d",f[0]+1);//因为是从0开始的 所以要+1
}
POJ 2533 动态规划入门 (LIS)的更多相关文章
- nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)
17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...
- POJ 2533 裸的LIS
A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- POJ 2533 最小上升子序列
D - POJ 2533 经典DP-最长上升子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let th ...
- 洛谷P1028 数的计算 题解 动态规划入门题
题目链接:https://www.luogu.com.cn/problem/P1028 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数 \(n\) ): 先输入一个自然数 \(n(n \ ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- POJ 2533 Longest Ordered Subsequence(裸LIS)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- LIS(n^2) POJ 2533 Longest Ordered Subsequence
题目传送门 题意:LIS(Longest Increasing Subsequence)裸题 分析:状态转移方程:dp[i] = max (dp[j]) + 1 (a[j] < a[i],1 ...
随机推荐
- Install-Package EntityFramework -version 5.0.0.0
Install-Package EntityFramework -version 5.0.0.0
- javascript 分页组件
自己写的一个简单的分页组件,主要功能还有实现都在JS中,html页面中只用增加一个放置生成分页的DIV,并给定容器的id. html结构如下: <ul class="paginatio ...
- python成长之路【第二篇】:列表和元组
1.数据结构数据结构是通过某种方式(例如对元素进行编号)组织在一起的数据元素的集合,这些数据元素可以是数字或者字符,甚至可以是其他数据结构.在Python中,最基本的数据结构是序列(sequence) ...
- win7下的ipython没有的问题
在笔记本上安装python2.7后,执行python是可以的,但是ipython却不行. 一.问题排查 在网上搜索了看到python与ipython的区别: 例如:ipython有tab补全功能,然后 ...
- 转!!URL 传+号到后台变空格问题解决方案
网上很多解决方法,但是前提是get请求(或者是post请求后面追加的参数),让我试了很久(我是post),没成功!引以为戒!! 今天在调试客户端向服务器传递参数时,参数中的“+”全部变成了空格,原因是 ...
- cxf的soap风格+spirng4+maven 客户端
上篇博客介绍了,cxf的soap风格的服务端,现在我们写客户端来调用 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0 ...
- 在eclipse中导入weka(小白在路上)
第一步:新建一个java工程,new->javaproject,假设工程名为wekatest 第二步:导入weka.jar 第三步:src关联 导入后有许多的.class文件,直接双击打开是看不 ...
- [笔记]CSS样式声明顺序
来自Bootstrap中文网编程规范 相关的属性声明应当归为一组,并按照下面的顺序排列: Positioning Box model Typographic Visual .declaration-o ...
- 使用C语言将IE收藏夹生成HTML
IE收藏夹里收藏的链接很多,查找也不方便,使用C编写一个小工具,可以将收藏夹里的链接文件生成到一个HTML文件上. 源码还有许多地方需要优化,后续我会优化,先分享出来.目的主要是为了练习C语言,这个代 ...
- ROS实际问题解决方法
1.建立软链接 在路径cd /etc/udev/rules.d中,建立例如50-rfid.rules的文件,它会根据文件名之前的50 51等判断优先级,50的优先级就大于51 如: KERNEL== ...