题目链接: http://poj.org/problem?id=2533

题意:第一个数n,接下来n个数,>  ....求最长上升子序列。

这道题有两种解法,第一种是通解,也适用于别的LIS。

代码1:

#include<cstdio>
#include<algorithm>
using namespace std; int a[],dp[]; int main()
{
int n;
while(scanf("%d",&n)==)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
dp[i]=;
}
int len=;
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
if(a[i]>a[j])
{
if(dp[j]+>=dp[i]) /// dp[i]=max(dp[i],dp[j]+1);
dp[i]=dp[j]+,dp[j];
}
len=max(len,dp[i]);
}
}
printf("%d\n",len);
}
return ;
}

代码2:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std; int a[],dp[];
int main()
{
int n,len;
while(scanf("%d",&n)==)
{
for(int i=; i<=n; i++)
scanf("%d",a+i);
dp[]=a[];
len=;
for(int i=; i<=n; i++)
if(a[i]>dp[len]) dp[++len]=a[i];
else dp[lower_bound(dp+,dp+len+,a[i])-dp]=a[i];
printf("%d\n",len);
}
return ;
}

poj2533 LIS的更多相关文章

  1. 【动态规划+二分查找】POJ2533&POJ1631最长上升子序列(LIS)

    POJ2533裸的LIS,时间复杂度为O(n^2) #include<iostream> #include<cstdio> using namespace std; +; in ...

  2. POJ2533:Longest Ordered Subsequence(LIS)

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

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

    本题大意:和LIS一样 本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i) 参考代码: # ...

  4. (线性DP LIS)POJ2533 Longest Ordered Subsequence

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

  5. POJ2533(KB12-N LIS)

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

  6. POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  7. 最长上升子序列算法(n^2 及 nlogn) (LIS) POJ2533Longest Ordered Subsequence

    问题描述: 一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的.对于给定的一个序列(a1, a2, ..., aN),我们可以得到一些上升的子序列 ...

  8. Lis日常维护

    1.[问题]护士站打印LIs条码,出来是PDF格式的 [解决]在文件夹Client\NeusoftLis\Xml\Print.xml中把BarcodePrint Name的值改成安装的斑马打印机名(不 ...

  9. uva10635 LIS

    Prince and PrincessInput: Standard Input Output: Standard Output Time Limit: 3 Seconds In an n x n c ...

随机推荐

  1. code vs1262 不要把球传我(组合数学) 2012年CCC加拿大高中生信息学奥赛

    1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解  查看运行结果     题目描述 De ...

  2. 在SpringMVC中获取request对象

    1.注解法 @Autowired private  HttpServletRequest request; 2. 在web.xml中配置一个监听 <listener> <listen ...

  3. 【leetcode】Find Minimum in Rotated Sorted Array I & II (middle)

    1. 无重复 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 ...

  4. Hibernate简单分页

    5.1 准备工作 建立项目,加入jar 建立hibernate.cfg.xml 建立pojo类和对应的映射文件 5.2 建立vo类PageEntity package org.guangsoft.vo ...

  5. openssl/asn1.h file not found的解决方法

    iOS 引入支付宝 缺少 #include <openssl/asn1.h>  报错     解决方法: 在 Building Settings -> Search Paths -& ...

  6. redis配置详情

    # Redis configuration file example # Note on units: when memory size is needed, it is possible to sp ...

  7. grep -v 排除多人字符串

    # egrep -v '^$|^#' /etc/httpd/conf/httpd.conf # grep -v '^$\|^#' /etc/httpd/conf/httpd.conf

  8. ****CodeIgniter使用cli模式运行,把php作为shell编程

    shell简介 在计算机科学中,Shell俗称壳(用来区别于核).而我们常说的shell简单理解就是一个命令行界面,它使得用户能与操作系统的内核进行交互操作. 常见的shell环境有:MS-DOS.B ...

  9. 解析PHP处理换行符的问题 \r\n

    一首先说说 \r 与\n的区别回车”(Carriage Return)和“换行”(Line Feed)这两个概念的来历和区别.在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model ...

  10. 【翻译二十二】java-并发之集合与原子变量

    Concurrent Collections The java.util.concurrent package includes a number of additions to the Java C ...