题目链接: 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. maven加载本地lib下的jar包(pom.xml)

    1.将本地jar放置到仓储库在jar包目录下 mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserve ...

  2. 【leetcode】 Longest Valid Parentheses (hard)★

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  3. asp.net 图片下载

    string fileName = "123.jpg";//图片名字                    string filePath = Server.MapPath(&qu ...

  4. ASP.NET 下载文件并继续执行JS解决方法

    需求说明:当用户点击按钮时使当前按钮为不可用,并打开新页面,关闭新页面时,按钮变为可用.并且如果不关闭新页面,当前按钮过10秒钟自动变为可用. 包含3个页面: 一.按钮页 前台代码:当刷新后采用js进 ...

  5. Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)

    ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...

  6. PullToRefreshScrollView嵌套SwipeMenuListView冲突问题解决

    参考: http://blog.csdn.net/u012255016/article/details/46048797 public class NoScrollSwipeMenuListView ...

  7. Codeforces Round #304 C(Div. 2)(模拟)

    题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...

  8. c# 扩展方法奇思妙用基础篇八:Distinct 扩展(转载)

    转载地址:http://www.cnblogs.com/ldp615/archive/2011/08/01/distinct-entension.html 刚看了篇文章 <Linq的Distin ...

  9. Delphi面向对象的可见性表示符

    Delphi能通过在声明域和方法的时候用protected.private.public.published和automated指示符来对对象提供进一步的控制.使用这些关键字的语法如下 TSomeOb ...

  10. ytu 1059: 判别该年份是否闰年(水题,宏定义)

    1059: 判别该年份是否闰年 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 222  Solved: 139[Submit][Status][Web ...