最长公共自序列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)的更多相关文章

  1. poj 2533 Longest Ordered Subsequence(线性dp)

    题目链接:http://poj.org/problem?id=2533 思路分析:该问题为经典的最长递增子序列问题,使用动态规划就可以解决: 1)状态定义:假设序列为A[0, 1, .., n],则定 ...

  2. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  3. Poj 2533 Longest Ordered Subsequence(LIS)

    一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  4. POJ 2533 Longest Ordered Subsequence(裸LIS)

    传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  5. POJ 2533 Longest Ordered Subsequence(dp LIS)

    Language: Default Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  6. 题解报告:poj 2533 Longest Ordered Subsequence(最长上升子序列LIS)

    Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...

  7. POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 38980   Acc ...

  8. POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)

    传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...

  9. POJ 2533——Longest Ordered Subsequence(DP)

    链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...

随机推荐

  1. [CSS]visibility 属性

    定义和用法 visibility 属性规定元素是否可见. 提示:即使不可见的元素也会占据页面上的空间.请使用 "display" 属性来创建不占据页面空间的不可见元素. 说明 这个 ...

  2. oracle 11g实验五——触发器的使用

    实验要求: 实验五 触发器的使用 实验目的 1.  理解触发器的概念.作用及分类: 2.  掌握触发器的创建.使用: 实验内容 1.  建立表orders:用于存储订单列表信息:表order_item ...

  3. Oracle wrap 测试的一些细节问题

    今天在做 wrap 的测试实验的时候,出现一个很奇怪的现象,就是加密不成功.具体表现为:1.加密后的文件大小为0kb. 2.加密后的文件仍然可视. 具体测试步骤如下: D:\Just4work\som ...

  4. Pair Project: Elevator Scheduler [电梯调度算法的实现和测试]:刘耀先-11061183,罗凡-11061174

    本次为我们两个人的第一次结对编程.从总体而言,我们对结对编程比单人编程略显不适应.但是经过一段时间的磨合,我们逐渐的习惯了这种编程方式. 1.  结对编程的优缺点 结对编程的优点: (1)       ...

  5. swfupload 上传控件的配置

    第一:下载swfupload控件,点击下载: 第二,解压缩后,在项目中添加这四个文件,如图: 然后,在你的js文件中添加这段代码: /** * *定义swfupload配置文件对象 **/ var s ...

  6. 数据结构-------单链表(C++)

    相关信息: /** * @subject 数据结构 实验2 * @author 信管1142班 201411671210 赖俊杰 * @project 单链表 * @time 2015年10月29日1 ...

  7. 数据结构---顺序表(C++)

    顺序表 是用一段地址连续的存储单元依次存储线性表的数据元素. 通常用一维数组来实现 基本操作: 初始化 销毁 求长 按位查找 按值查找 插入元素 删除位置i的元素 判空操作 遍历操作 示例代码: // ...

  8. JSP页面之${fn:}内置函数

    函数列表: 函数名 函数说明 使用举例 fn:contains 判断字符串是否包含另外一个字符串 <c:if test="${fn:contains(name, searchStrin ...

  9. 1091-Black Vienna

    描述 This problem is based on the game of Black Vienna. In this version there are three players and 18 ...

  10. nginx Location配置总结(转)

    本文部分转自:http://cssor.com/nginx-location-configuration.html 一. 开头 语法规则: location [=|~|~*|^~] /uri/ { … ...