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 ...
随机推荐
- Delphi的TService的輸入桌面切換(服务程序)(windows登录界面如何截图)(使用了OpenDesktop和GetThreadDesktop等API)
dfm: object CopyDeskService: TCopyDeskService OldCreateOrder = False OnCreate = ServiceCreate OnD ...
- xPool - 基于mysqlclient的mysql的c++连接池 - xnhcx的个人空间 - 开源中国社区
xPool - 基于mysqlclient的mysql的c++连接池 - xnhcx的个人空间 - 开源中国社区 xPool - 基于mysqlclient的mysql的c++连接池
- css中的hover ,关于li与a标签的问题
<head> <style> ul li a:hover{ background-color: red; } </style></head><ul ...
- 100M 宽带办理
http://zj.189.cn/zhuanti/kdsbz#%E5%8D%95%E5%AE%BD%E5%B8%A6%E7%89%B9%E6%83%A0
- Android常用控件之RatingBar的使用
RatingBar控件比较常见就是用来做评分控件,先上图看看什么是RatingBar 在布局文件中声明 <?xml version="1.0" encoding=" ...
- 14.3.5.1 An InnoDB Deadlock Example
14.3.5 Deadlocks in InnoDB 14.3.5.1 An InnoDB Deadlock Example 14.3.5.2 Deadlock Detection and Rollb ...
- sql,nosql
1. 关系型数据库 关系型数据库,是指采用了关系模型来组织数据的数据库. 关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐渐成 ...
- fragment Trying to instantiate a class com.example.testhuanxindemo.MyFragment that is not a Fragmen
在使用fragment的时候,先创建了一个fragment,然后为他创建布局,并在oncreateview中返回载入该视图的后返回的view,在activity的布局文件里,使用xml布局,用frag ...
- 【机器学习】SVM核函数
知识预备 1. 回顾:logistic回归出发,引出了SVM,即支持向量机[续]. 2. Mercer定理:如果函数K是上的映射(也就是从两个n维向量映射到实数域).那么如果K是一个有效核函数(也称 ...
- Android周报
Android周报 原文 http://www.race604.com/android-weekly-25/ 文章/教程 使用 Kotlin 开发 Android 应用系列 看起来用 Kotli ...