POJ 2533-Longest Ordered Subsequence(DP)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 34454 | Accepted: 15135 |
Description
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
Output
Sample Input
7
1 7 3 5 9 4 8
Sample Output
4
最长上升子序列。 。orz 傻逼竟然直接把dp[n]输出了 后来wa了一时还没反应过来。。
dp[i]代表以i为结尾的最长上升子序列的长度,but dp[n]不一定最长。。事实上整个dp数组就是无序的了。 。 能够sort后输出
O(n*n)渣比写法
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 1010
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
int n,dp[maxn],a[maxn];
void solve()
{
for(int i=2;i<=n;i++)
for(int j=1;j<i;j++)
if(a[i]>a[j]&&dp[i]<=dp[j])
dp[i]=dp[j]+1;
sort(dp+1,dp+n+1);
printf("%d\n",dp[n]);
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
dp[i]=1;
scanf("%d",&a[i]);
}
solve();
}
return 0;
}
POJ 2533-Longest Ordered Subsequence(DP)的更多相关文章
- POJ 2533——Longest Ordered Subsequence(DP)
链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 Acc ...
- POJ 2533 Longest Ordered Subsequence(dp LIS)
Language: Default Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- POJ 2533 Longest Ordered Subsequence(裸LIS)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)
传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...
- poj 2533 Longest Ordered Subsequence(线性dp)
题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定 ...
- POJ 2533 Longest Ordered Subsequence (LIS DP)
最长公共自序列LIS 三种模板,但是邝斌写的好像这题过不了 N*N #include <iostream> #include <cstdio> #include <cst ...
随机推荐
- 设计模式 - 装饰者模式(Decorator Pattern) Java的IO类 用法
装饰者模式(Decorator Pattern) Java的IO类 用法 本文地址: http://blog.csdn.net/caroline_wendy/article/details/26716 ...
- android之写文件到sd卡
1.main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- Delphi调用C++导出的QT类
打开VS2008创建一个dll项目(创建了一个QT Library项目),新建头文件q4dapplication.h定义纯虚类: #ifndef Q4DAPPLICATION#define Q4DAP ...
- 树莓派玩耍笔记4 -- 树莓派ssh党必备的配置
1. 关闭桌面显示 对于ssh 党.当然不须要系统花费资源在显示上. 所以我们先在 "raspi-conifg" 下选择默认启动为Text 启动(这好像也是Raspbian 的默认 ...
- Delphi中类的运行期TypeInfo信息结构说明
Delphi中类的运行期TypeInfo信息结构说明 CnPack 开源软件项目 2007-09-19 21:55:58 Delphi中类的运行期TypeInfo信息结构说明作者:刘啸CnPack开发 ...
- VCL改变主窗体的方法
使用如下语句即可Pointer((@Application.MainForm)^) := Form1; 仔细想想和Pointer((Application.MainForm)) := Form1;有什 ...
- LCA 最近公共祖先 tarjan离线 总结 结合3个例题
在网上找了一些对tarjan算法解释较好的文章 并加入了自己的理解 LCA(Least Common Ancestor),顾名思义,是指在一棵树中,距离两个点最近的两者的公共节点.也就是说,在两个点通 ...
- 深入探讨:LBS是一种工具而非一种模式
移动互联网的快速发展,带动着移动互联网应用的不断创新.从2010起,LBS的概念就在中国迅速兴起,但到了2011年底提供LBS服务的企业从最多50家已经降至仅剩15家.投行在看好移动互联网的同时又对L ...
- 算法起步之Dijkstra算法
原文:算法起步之Dijkstra算法 友情提示:转载请注明出处[作者 idlear 博客:http://blog.csdn.net/idlear/article/details/19687579 ...
- _tcscat在Debug和Release根据问题
背景: 因此,例如,在下面的代码段,作用是得到的路径当前程序(C:\work\A.exe),然后"A.exe"拆除,组装的"C:\work\inject.dll" ...