(线性DP LIS)POJ2533 Longest Ordered Subsequence
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 66763 | Accepted: 29906 |
Description
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
Output
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4 最长递增子序列问题,水题。理解好状态转移式怎么得到就行了。
状态转移式是d(i) = max(dp[j] + 1,dp[i])(a[i] > a[j])(j < i) (如果为最长不下降子序列的话a[i] >= a[j]就行,并且j < i);其中dp[i]要先为1,因为无论如何这个子序列的长度的最小情况为1。
打表就行
对了,最后得到的dp[i]中i从1到n时,各自的dp[i]代表前i个数的最长递增子序列的最长长度。不一定dp[n]是最大的,要先比较,从中选出最大的。 C++ 代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = ;
int a[maxn],dp[maxn];
int main(){
int n;
memset(a,,sizeof(a));
scanf("%d",&n);
for(int i = ; i < n; i++){
cin>>a[i];
}
memset(dp,,sizeof(dp));
for(int i = ; i < n; i++){
dp[i] = ;
for(int j = ; j < i; j++){
if(a[i] > a[j] && dp[j] + > dp[i])
dp[i] = dp[j] + ;
}
}
int ans = -;
for(int i = ; i < n; i++){
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
return ;
}
(线性DP LIS)POJ2533 Longest Ordered Subsequence的更多相关文章
- POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)
题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- POJ2533——Longest Ordered Subsequence(简单的DP)
Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- [POJ2533]Longest Ordered Subsequence<dp>
题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...
- POJ2533 Longest Ordered Subsequence 【最长递增子序列】
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32192 Acc ...
- poj-2533 longest ordered subsequence(动态规划)
Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- POJ2533 Longest ordered subsequence
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 41984 Acc ...
- POJ2533 Longest Ordered Subsequence (线性DP)
设dp[i]表示以i结尾的最长上升子序列的长度. dp[i]=max(dp[i],dp[j]+1). 1 #include <map> 2 #include <set> 3 # ...
- POJ-2533.Longest Ordered Subsequence (LIS模版题)
本题大意:和LIS一样 本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i) 参考代码: # ...
- POJ2533:Longest Ordered Subsequence(LIS)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
随机推荐
- MySQL——基础操作
参考博客:http://www.cnblogs.com/wupeiqi/articles/5713315.html 1.创建用户.授权(默认root,密码为空) 创建: create user 'al ...
- Ubuntu install flash
Software&Updates - Other Software - Canonical Parners sudo apt install adobe-flashplugin
- EFI Windows 7 activition
mountvol X: /s copy SLIC.aml X:\EFI\CLOVER\ACPI\WINDOWS BOOTICE X:\EFI\CLOVER\CLOVERX64.efi slmgr -i ...
- python字典与集合操作
字典操作 字典一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 语法: info = { 's1': "jack", 's3' ...
- linux常用命令(个人总结)
1.快捷键: ctrl + l --------------------清屏 ctrl + c --------------------退出当前命令 ctrl + ...
- Linux各目录及每个目录的详细介绍
http://www.cnblogs.com/duanji/p/yueding2.html
- HDU4341-Gold miner-分组DP
模拟黄金矿工这个游戏,给出每一个金子的位置和所需时间,计算在给定时间内最大收益. 刚看这道题以为金子的位置没什么用,直接DP就行,WA了一发终于明白如果金子和人共线的话只能按顺序抓. 这就是需要考虑先 ...
- Android LinearLayout 渐变背景
更多 参考 Drawable Resources | Android Developers main_header.xml: <?xml version="1.0" enc ...
- Double.valueOf(0.0D) 分析
private Double price = Double.valueOf(0.0D); 查看Java API 文档如下: doubleValue public double doubleValue( ...
- 故障排错-ping dup!
ping DUP! ping一个vc中虚拟机的地址发现如下,出现了DUP! . 解决方式如下: 1.根据mac地址找到虚拟机网卡的端口组 然后编辑绑定和故障切换,切换负责平衡