给定一个序列,里面的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. mysql5.5主从同步复制配置

    在上篇文章<烂泥:学习mysql数据库主从同步复制原理>中,我们介绍了有关mysql主从复制的基本原理.在这篇文章中,我们来实际测试下mysql5.5的主从同步复制功能. 注意mysql5 ...

  2. 自定义Panel中添加依赖属性需要注意的问题

    今天帮忙同事调试一个自定义Panel的问题, 很奇怪, 利用Binding可以通过ItemSource来添加控件,但是在Listbox的xaml里添加几个ListboxItem却报异常: Visual ...

  3. makefile 基础知识

    $@    目标文件名 $< 第一个依赖文件名 $^ 规则所有依赖文件列表 如果不想让执行语句被打印出来,就在语句前面加上@符号 模式规则 %.o:%.c 后缀规则 .c.o 生成单进程的Mak ...

  4. telnet IP:ERROR

    实验环境:CentOS6.8 主机:172.16.xxx.xxx:80 客户端:172.16.xxx.xxx [root@www ~18:32:27]#telnet 172.16.xxx.xxx 80 ...

  5. MS SQL update set select

    有张表a,已经有数据 再有张表b,也已查询出数据 两张表有外键关联 需求如下: 更新表a中的某个字段,这个字段要加上(都是int型的数据)对应表b中的数据作为更新的最终数据 )) from #libL ...

  6. ps查看进程

    ps:要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,而ps命令就是最基本同时也是非常强大的进程查看命令.使用该命令可以确定有哪些进程正在运行和运行的状态.进程是否结束. ...

  7. Angular12 学习angular2前的热身准备

    1 ECMA European Computer Manufactures Association 这个组织的目标是评估,开发和认可电信和计算机标准. 百度百科:点击前往 ECMA65:满足ECMA标 ...

  8. 具体问题:3、hibernate跟Mybatis/ ibatis 的区别,为什么选择?

    第一章     Hibernate与MyBatis Hibernate 是当前最流行的O/R mapping框架,它出身于sf.net,现在已经成为Jboss的一部分. Mybatis 是另外一种优秀 ...

  9. PAM认证

    PAM认证 摘自: http://www.cnblogs.com/shenxm/p/8451889.html PAM(Pluggable Authentication Modules) Sun公司于1 ...

  10. 截止JDK1.8版本,java并发框架支持锁包括?

    读写锁 自旋锁 乐观锁