HDU 5773 The All-purpose Zero (变形LIS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773
0可以改变成任何数,问你严格递增的子序列最长是多少。
猜测0一定在最长上升子序列中用到,比如2 0 0 3 5 6,可以变为2 3 4 3 5 6。
那我们先算出0的个数,然后每次遇到0就把后面一开始不是0的-1,算出剩下数的最长上升子序列(nlogn),然后加上0的个数。
//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int inf = 0x3f3f3f3f;
int a[N], dp[N], b[N]; // dp[i]:长度为i的上升子序列中最后元素的最小值 int main()
{
int t, n;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%d", &n);
int dec = , index = ;
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
if(a[i] == ) {
++dec;
} else {
a[i] -= dec;
b[++index] = a[i];
}
dp[i] = inf;
}
for(int i = ; i <= index; ++i) {
*lower_bound(dp + , dp + index + , b[i]) = b[i];
}
printf("Case #%d: %d\n", ca, lower_bound(dp + , dp + n + , inf) - dp - + dec);
}
return ;
}
HDU 5773 The All-purpose Zero (变形LIS)的更多相关文章
- hdu 5773 The All-purpose Zero 最长上升子序列+树状数组
题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...
- HDU 3094 树上删边 NIM变形
基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...
- HDU 5773 The All-purpose Zero(O(nlgn)求LIS)
http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍L ...
- HDU 5773:The All-purpose Zero(贪心+LIS)
http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description ?? gets an ...
- HDU 5773 The All-purpose Zero 求LIS
求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以 ...
- HDU 5773 The All-purpose Zero 脑洞LIS
给定一个序列,里面的0是可以任变的.问变化后最长的LIS的长度 首先,0全部选上是不亏的.这个不知道怎么说,YY一下吧. 最关键的就是解决2 0 0 3 这种问题了. 注意到这个序列的LIS应该是3 ...
- HDU 1087 Super Jumping! Jumping! Jumping! ——(LIS变形)
和之前那个长方体最大高度是换汤不换药的题目.每次找之前最大的一个能接的接上即可.代码如下: #include <stdio.h> #include <algorithm> #i ...
- hdu 5773 The All-purpose Zero 线段树 dp
The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an seq ...
- 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何 ...
随机推荐
- hdu 4937 Lucky Number
虽然算法清晰的不能再清晰,但是实现总是边角料错这错那. 题目大意: 给出n,找出一些进制,使得n在该进制下仅为3,4,5,6表示 解题思路: 首先,4-10000进制直接枚举计算出每一位 此外,最多只 ...
- 宏UT_LIST_ADD_FIRST
/*******************************************************************//** Adds the node as the first ...
- UVa 253 Cube paiting
题意:输入两个骰子,判断是否等价 因为每一个面可以作顶面,共6*4种情况,枚举就可以了 #include<iostream> #include<cstdio> #include ...
- Darwin Streaming Server用vs2005编译运行过程
原创. 一:编译 Darwin6.0.3版本是最新版本,也提供了.dsw文件.但是使用vs2005和vc6是编译不过的.所以,采用Darwin5.5.5版本.使用vc6打开WinNTSupport文件 ...
- poj 1201/zoj 1508 intervals 差分约束系统
// 思路 : // 图建好后 剩下的就和上一篇的 火烧连营那题一样了 求得解都是一样的 // 所以稍微改了就过了 // 最下面还有更快的算法 速度是这个算法的2倍#include <ios ...
- <八>面向对象分析之UML核心元素之分析类
一:基本概念 ---->在那大数项目中,分析类是被忽视的一种非常有用的元素. ---->分析类用于获取系统中主要的“职责簇”,他们代表系统的原型类,是系统必须处 ...
- Delphi Unable to invoke Code Completion due to errors in source code
这时因为在.pas文件中存在delphi无法识别的编码,也就是说.pas文件中的字符并非是纯粹的可由文本文件编辑器所能识别的编码.所以,delphi就不可能有效地解释这些编码.因而就出现了自动代码提示 ...
- golang学习之指针、内存分配
func pointer_test() { //空指针,输出为nil var p *int fmt.Printf("p: %v\n", p) //指向局部变量,变量值初始为0 va ...
- Delphi word 颜色
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, ...
- asp.net中遍历界面上所有控件进行属性设置
* 使用方法: * 前台页面调用方法,重置: protected void Reset_Click(object sender, EventArgs e) { ...