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

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

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

题目解析:

这两道题都是直接求最长上升子序列,没什么好说的。

POJ 3903这题n为1000000,如果用n^2的算法肯定超时,所以要选择nlogn的算法。都是简单题。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define eps 1e-9
using namespace std;
int n,len,a[],d[];
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int we;
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
len=;
d[len]=a[];
for(int i=; i<=n; i++)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("%d\n",len);
}
return ;
}

POJ1631:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define eps 1e-9
using namespace std;
int n,len,a[],d[];
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int we,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
len=;
d[len]=a[];
for(int i=; i<=n; i++)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("%d\n",len);
}
return ;
}

POJ1887Testing the CATCHER:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int n,a[],d[],len;
int er(int q[],int l,int r,int key)//好好研究二分
{
int mid;
while(l<=r)
{
mid=(l+r)/;
if(q[mid]==key)
{
return mid;
}
else if(q[mid]>key)
{
r=mid-;
}
else l=mid+;
}
return l;
}
int main()
{
int tt,we,K=;
while(scanf("%d",&a[])!=EOF&&a[]!=-)
{
tt=;
while(scanf("%d",&a[++tt])!=EOF&&a[tt]!=-)
;
tt-=;
len=;
d[len]=a[tt];
for(int i=tt-; i>=; i--)
{
if(a[i]>d[len])
{
d[++len]=a[i];
}
else
{
we=er(d,,len,a[i]);
d[we]=a[i];
}
}
printf("Test #%d:\n",++K);
printf(" maximum possible interceptions: %d\n\n",len);
}
return ;
}

POJ3903Stock Exchange&&POJ1631Bridging signals最长上升子序列 &&POJ1887Testing the CATCHER(最长下降子序列)(LIS模版题)的更多相关文章

  1. poj 3903 Stock Exchange(最长上升子序列,模版题)

    题目 #include<stdio.h> //最长上升子序列 nlogn //入口参数:数组名+数组长度,类型不限,结构体类型可以通过重载运算符实现 //数组下标从1号开始. int bs ...

  2. 最长下降子序列O(n^2)及O(n*log(n))解法

    求最长下降子序列和LIS基本思路是完全一样的,都是很经典的DP题目. 问题大都类似于 有一个序列 a1,a2,a3...ak..an,求其最长下降子序列(或者求其最长不下降子序列)的长度. 以最长下降 ...

  3. 最长不下降子序列(LIS)

    最长上升子序列.最长不下降子序列,解法差不多,就一点等于不等于的差别,我这里说最长不下降子序列的. 有两种解法. 一种是DP,很容易想到,就这样: REP(i,n) { f[i]=; FOR(j,,i ...

  4. 最长不下降子序列 O(nlogn) || 记忆化搜索

    #include<stdio.h> ] , temp[] ; int n , top ; int binary_search (int x) { ; int last = top ; in ...

  5. BUY LOW, BUY LOWER_最长下降子序列

    Description The advice to "buy low" is half the formula to success in the bovine stock mar ...

  6. tyvj 1049 最长不下降子序列 n^2/nlogn

    P1049 最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 ...

  7. 最长不下降子序列的O(n^2)算法和O(nlogn)算法

    一.简单的O(n^2)的算法 很容易想到用动态规划做.设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i&g ...

  8. 最长不下降子序列//序列dp

    最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 最长不下降 ...

  9. 【tyvj】P1049 最长不下降子序列

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数 第二行n个数 输出格式 最长不下降子序列的长度 测 ...

随机推荐

  1. js学习笔记22----BOM属性和方法

    BOM基本概念 : Browser Object Model 浏览器对象模型. BOM属性: window.navigator.userAgent : 浏览器信息 判断是否是某个浏览器,可以用 ind ...

  2. 第二百六十四节,Tornado框架-基于正则的动态路由映射分页数据获取计算

    Tornado框架-基于正则的动态路由映射分页数据获取计算 分页基本显示数据 第一步.设置正则路由映射配置,(r"/index/(?P<page>\d*)", inde ...

  3. Android_Zip解压缩工具

    public class ZipUtil { public ZipUtil(){ } /** * DeCompress the ZIP to the path * @param zipFileStri ...

  4. 【转】关于OnPaint的工作机制

    转载出处:http://blog.csdn.net/foreverhuylee/article/details/21889025 用了两年的VC++,其实对OnPaint的工作原理一直都是一知半解.这 ...

  5. POJ 3468 A Simple Problem with Integers(线段树功能:区间加减区间求和)

    题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit ...

  6. Hibernate_day01--课程安排_Hibernate概述_Hibernate入门

    Hibernate_day01 Hibernate课程安排 今天内容介绍 WEB内容回顾 JavaEE三层结构 MVC思想 Hibernate概述 什么是框架 什么是hibernate框架(重点) 什 ...

  7. 应用开发之WinForm环境

    本章简言 上一章笔者讲到关于IO文件操作类,了解如何处理文件流.从这一章开始笔者将讲解相对比较高级的知识点.而本章笔者就对WinForm开发的知识点进行讲解和引导.现在很多业务都是面向于B/S模式的开 ...

  8. 延迟加载JavaScript

    上代码: 这段代码放到HTML文档的</body>标签之前(靠近HTML文档底部).外部脚本的名称为defer.js. <script type="text/javascr ...

  9. 虚拟机VMWare安装苹果系统MacOS详细教程(联网设置,全屏插件、文件互传)

    运行环境: VMware® Workstation 12 Pro(自行安装,或者用这个) 推荐(下面以10.11.6版本做的教程,但是安装时推荐使用此版本安装然后升级到10.11.6):MacOS X ...

  10. HDU 1866 A + B forever!

    A + B forever! Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...