给定一个序列,里面的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. 实用的原生js图片轮播

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. android获取时间差的方法

    本文实例讲述了android获取时间差的方法.分享给大家供大家参考.具体分析如下: 有些时候我们需要获取当前时间和某个时间之间的时间差,这时如何获取呢? 1. 引用如下命名空间: import jav ...

  3. 十六、xx.xx.xx格式版本号大小比较

    DELIMITER $$ USE `deshangshidai`$$ DROP FUNCTION IF EXISTS `STRCMP_MY_VERSION`$$ CREATE DEFINER=`roo ...

  4. shell入门-grep-3-egrep

    grep -E == egrep [root@wangshaojun ~]# grep --color 'r\?o' 1.txt == egrep --color 'r?o' 1.txt ^C[roo ...

  5. redis的 key string hash list set sorted set 常用的方法

    redis 安装文件:  http://blog.csdn.net/tangsilai/article/details/7477961 ==============================   ...

  6. 《Spring实战》系列之Bean的装配-Days01

    1 自动化装配bean Spring通过两个方面实现对bean的自动装配 1 ) 组件扫描(component scaning):Spring会自动发现Spring上下文中的bean 2 ) 自动装配 ...

  7. elasticsearch2.x插件之一:kibana

    介绍: 要说kibana,就不得不先说一下logstash.这里呢,先要讲个故事.故事是开头是这样的,Logstash早期曾经自带了一个特别简单的logstash-web用来查看ES中的数据,其功能太 ...

  8. 项目一:第七天 CRM 和bos系统实现定区关联客户,关联快递员. 通过CXF框架实现

    定区关联客户 需求:为了快递方便客户下订单(发快递),派快递员上门取件.  所以说需要让定区关联客户(知道客户属于哪个定区),定区跟快递员关系:多对多.知道让哪个快递员上门取件. 将CRM系统中,客户 ...

  9. AT指令集

    通用指令 at+cala   设置警报日期和时间 at+cgmi  厂家认证请求,返回模块厂家信 at+cgmm 模式认证请求,返回模块使用频段 at+cgmr 修正认证请求,返回软件版本 at+cg ...

  10. glib-2.40编译安装

    1 安装glib库所需要的依赖库: libffi-.tar.gz glib-.tar.xz 安装依赖库libffi: tar xf libffi-.tar.gz cd libffi- ./config ...