给定一个序列,里面的0是可以任变的。问变化后最长的LIS的长度

首先,0全部选上是不亏的。这个不知道怎么说,YY一下吧。

最关键的就是解决2 0 0 3

这种问题了。

注意到这个序列的LIS应该是3

也就是你求LIS的时候,是不能包括0的,因为0是最后全部加上去的。这样你求到的LIS只能是1.

再来一组数据

2 0 0 3 0 0 4

这样的LIS是5,也就是你求到的LIS只能是1.

这样的话,只有2 1 0求到的LIS是1了。

也就是每个数减去它前面出现过多少个0,再求一次LIS.

关键要抓住0要全部用上,想到每个数减去前面有多少个0,比较难想到。抓住0要全部用上。列几组数据,慢慢推还可以。

(其实是我比较水,想不懂)

现在还有点难理解

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int a[maxn];
int b[maxn];
bool pos[maxn];
int dp[maxn];
int dp_up (int a[],int lena)
{
int begin=;
while (pos[begin]) begin++;
b[]=a[begin];
int lenb=;
for (int i=begin+;i<=lena;++i)
{
if (pos[i]) continue;
if (a[i] > b[lenb])
{
b[++lenb] = a[i];
}
else
{
int pos = lower_bound(b+,b++lenb,a[i]) - b;
b[pos] = a[i];
}
}
return lenb;
}
int f; void work ()
{
memset(pos,,sizeof pos);
memset(dp,,sizeof dp);
int n;
scanf("%d",&n);
int begin=-;
for (int i=;i<=n;++i)
{
scanf("%d",&a[i]);
if (a[i]==) dp[i] = dp[i-]+;
else dp[i]=dp[i-];
if (a[i]==) pos[i]=;
}
if(dp[n]==n)
{
printf ("Case #%d: %d\n",++f,n);
return ;
}
for (int i=;i<=n;++i)
{
if (pos[i]) continue;
else a[i] -= dp[i];
}
int ans = dp_up(a,n);
printf ("Case #%d: %d\n",++f,ans+dp[n]);
return ;
}
int main()
{
#ifdef LOCAL
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while (t--) work();
return ;
}

HDU 5773 The All-purpose Zero 脑洞LIS的更多相关文章

  1. hdu 5773 The All-purpose Zero 最长上升子序列+树状数组

    题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...

  2. HDU 5773 The All-purpose Zero(O(nlgn)求LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍L ...

  3. HDU 5773:The All-purpose Zero(贪心+LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description   ?? gets an ...

  4. HDU 5773 The All-purpose Zero (变形LIS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773 0可以改变成任何数,问你严格递增的子序列最长是多少. 猜测0一定在最长上升子序列中用到,比如2 ...

  5. 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]) 用二分可以 ...

  6. hdu 5773 The All-purpose Zero 线段树 dp

    The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an seq ...

  7. 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何 ...

  8. HDU 5773 The All-purpose Zero(树状数组)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长 ...

  9. HDU 1087 最长不下降子序列 LIS DP

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

随机推荐

  1. lvs-nat搭建httpd

    拓扑图: #172.16.252.10 [root@~ localhost]#route -n Kernel IP routing table Destination Gateway Genmask ...

  2. Zend Server 安装与配置图文教程

    Zend Server是一款专业的PHP Web开发应用服务器,一些初次接触并使用此程序的朋友可能不太了解安装方法,本文为您提供了Zend Server 安装与配置图文教程,欢迎大家阅读,并提出自己的 ...

  3. webrower + CEF

    理解WebKit和Chromium: Content API和CEF3 标签:               apiAPIAPibrowserchromeChromehtml5HTML5Html5web ...

  4. LAMP 1.2 Apache编译安装

    1.下载                                                                                                 ...

  5. DES加密/解密

    /// <summary> /// DES加密/解密类. /// </summary> public class DESEncrypt { #region ========加密 ...

  6. Flask07 Jinja2模板测试器、控制语句IF/FOR、变量/块 赋值、作用域、块级作用域

    1 测试器及其使用 在模板中的 {{}} 可以书写测试器,格式如下 {{ 变量 is 测试器名称  }} 1.1 在python中导入 Jinja2 的模板 from jinja2 import te ...

  7. AngularJs(Part 11)--自定义Directive

    先对自定义Directive有一个大体的映像 myModule.directive('myDirective',function(injectables){ var directiveDefiniti ...

  8. Learning Python 003 缩进

    Python 缩进 Python的代码中不使用{}大括号来来表示一个代码块,而是使用缩进方式.像下面这段代码: # print absolute value of an integer: a = 10 ...

  9. SDK和JDK的区别

    刚开始工作时,还以为两者是一样的,只是版本换新给了个新名字罢了.最近又关注到这个问题,才发现自己大错特错,故整理了下分享给大家,共勉! jdk,是Java开发工具包,主要用于编写Java程序:也就是说 ...

  10. C++ STL 的各结构实现

    C++ STL 的实现: 1.vector  底层数据结构为数组 ,支持快速随机访问 2.list    底层数据结构为双向链表,支持快速增删 3.deque   底层数据结构为一个中央控制器和多个缓 ...