题目链接: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. Spring MVC学习之三:处理方法返回值的可选类型

    http://flyer2010.iteye.com/blog/1294400 ———————————————————————————————————————————————————————————— ...

  2. Emmet快速编写HTML代码

    缩写是Emmet工具的核心,这些特殊的表达式通过Emmet解析并转化为结构化的代码块,而语法用CSS选择器,HTML标签和一些Emmet特定的代码生成,所以对于任何一个前端开发人员都可以很容易地掌握和 ...

  3. 为什么逻辑斯特回归(logistic regression)是线性模型

    一个典型的logistic regression模型是: 这里明明用了非线性函数,那为什么logistic regression还是线性模型呢? 首先,这个函数不是f(y,x)=0的函数,判断一个模型 ...

  4. &lt;LeetCode OJ&gt; 217./219. Contains Duplicate (I / II)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  5. COCOS2D-X多层单点触摸分发处理方案?

    如今的问题是点击button的时候,会触发底层的触摸事件,怎么不触发底层的触摸事件啊?  

  6. db2 improt from coldel0x7c

    db2 load from "C:\20110816\20110816_BankEnterpri seCA.txt" OF del modified by coldel0x7c r ...

  7. jQuery实现瀑布流布局详解(PC和移动端)

    首先我们将如下样式的若干个单元写进body中,并将“box”向左浮动: <div class="box">  <img class="img" ...

  8. 如何在ChemDraw中输入℃温度符号

    化学反应常常对于温度是有一定要求的,所以用ChemDraw化学绘图工具在绘制化学反应的时候常常会用到℃温度符号.但是一些才接触ChemDraw的用户朋友不知道怎么输入℃.针对这种情况本教程来给大家分享 ...

  9. VC++:ActiveX Test Container

    VC++6.0安装后包含了ActiveX Test Container工具,位置为: "C:\Program Files (x86)\Microsoft Visual Studio\Comm ...

  10. 数据驱动ddt+excel数据读取

    我们可以将测试数据用excel存储,再用ddt去传入,不过我们需要安装对应的库,因为python是无法操作excel的 1.安装第三方库xlrd 2.创建一个excel表格,将需要测试的数据保存 3. ...