POJ 2533 Longest Ordered Subsequence (LIS DP)
最长公共自序列LIS
三种模板,但是邝斌写的好像这题过不了
N*N
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = ;
int a[],dp[],n;
int Lis(){
dp[]=;
int ans=;
int temp=;
for(int i=;i<=n;i++){
temp=;
for(int j=;j<i;j++){
if(dp[j]>temp&&a[i]>a[j]){
temp=dp[j];
}
}
dp[i]=temp+;
if(dp[i]>ans){
ans=dp[i];
}
}
return ans;
}
int main(){
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
printf("%d\n",Lis());
}
return ;
}
N*logn
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std; int a[],dp[],c[],n; int bin(int sizee,int k)
{
int l = ,r = sizee;
while(l<=r)
{
int mid = (l+r)/;
if(k>c[mid] && k<=c[mid+])
return mid+;
else if(k<c[mid])
r = mid-;
else
l = mid+;
}
} int LIS()
{
int i,j,ans=;
c[] = a[];
dp[] = ;
for(i = ; i<=n; i++)
{
if(a[i]<=c[])
j = ;
else if(a[i]>c[ans])
j = ++ans;
else
j = bin(ans,a[i]);
c[j] = a[i];
dp[i] = j;
}
return ans;
} int main()
{
int i;
while(~scanf("%d",&n))
{
for(i = ; i<=n; i++)
scanf("%d",&a[i]);
printf("%d\n",LIS()); }
return ;
}
没有AC
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
#include<cmath>
const int inf=0x3f3f3f3f;
using namespace std;
const int MAXN=;
int a[MAXN],b[MAXN];
int Serch(int num,int low,int high) {
int mid;
while(low<=high) {
mid=(low+high)/;
if(num>=b[mid])
low=mid+;
else high=mid-;
}
return low;
}
int Dp(int n) {
int i,len,pos;
b[]=a[];
len=;
for(i=; i<=n; i++) {
if(a[i]>=b[len]) {
len=len+;
b[len]=a[i];
} else {
pos=Serch(a[i],,len);
b[pos]=a[i];
}
}
return len;
} int main() {
int n;
while(~scanf("%d",&n)) {
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
printf("%d\n",Dp(n));
}
}
POJ 2533 Longest Ordered Subsequence (LIS DP)的更多相关文章
- poj 2533 Longest Ordered Subsequence(线性dp)
题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定 ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- 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(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 subsequence ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 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 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...
随机推荐
- cms开发笔记2
1 创建数据库表 //配置文件CREATE TABLE IF NOT EXISTS `mc_config` ( `en_name` varchar(80) NOT NULL, `ch_name` va ...
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode
[spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowe ...
- 温故知新——json
Json简介 Json(JavaScript Object Notation)是一种轻量级的数据交换格式.它是基于javascript(Standard ECMA-262 3rd Edition - ...
- ASP.NET 学习小记 -- “迷你”MVC实现(2)
Controller的激活 ASP.NET MVC的URL路由系统通过注册的路由表对HTTO请求进行解析从而得到一个用户封装路由数据的RouteData对象,而这个过程是通过自定义的UrlRoutin ...
- uvision4 ide已停止工作
情景描述: 笔者安装了新系统WIN8.1,装上了MDKV4.72.MDK编译程序可以正常工作,可是只要当我“下载程序”或者“调试程序”的时候就提示“uvision4 ide已停止工作”,迫不得已只能关 ...
- java转义字符(转载)
转载自:http://blog.163.com/dingyi_57@126/blog/static/110479195200911229337281/ 一.为什么要使用转义字符? 1. HTML中& ...
- js 拼接 三列做为一行
function Ajax_GetCourseAndResource(data) { $(".ol-course-list").empty(); var html = " ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- 如何获得iphone设备的剩余空间
在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间. 用法:先引入头文件 #include <sys/param.h> #in ...
- nutch 采集到的数据与实际不符
现象,这个网站我总计能抽取将近500个URL,但实际只抽取了100条 解析:nutch默认从一个页面解析出的链接,只取前 100 个. <property> <name>db. ...