给定一个序列,里面的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. bzoj 1185 最小矩形覆盖 —— 旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 枚举一条边,维护上.左.右方的点: 上方点到这条边距离最远,所以用叉积求面积维护: 左 ...

  2. Java程序打包成exe可执行文件

    前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...

  3. C语言计算日期间隔天数的经典算法解析

    #include <stdio.h> #include <stdlib.h> int day_diff(int year_start, int month_start, int ...

  4. net start sql server (instance)

    如何启动 SQL Server 实例(net 命令) 其他版本   可以使用 Microsoft Windows net 命令启动 Microsoft SQL Server 服务. 启动 SQL Se ...

  5. Jquery隐藏相同name的div

    $("div:[name=divName]").hide(); divName(自己div的Name)

  6. 没办法,SVD就讲的这么好

    2)奇异值: 下面谈谈奇异值分解.特征值分解是一个提取矩阵特征很不错的方法,但是它只是对方阵而言的,在现实的世界中,我们看到的大部分矩阵都不是方阵,比如说有N个学生,每个学生有M科成绩,这样形成的一个 ...

  7. 3.JasperReports学习笔记3-在浏览器生成PDF文件

    转自:https://i.cnblogs.com/posts?categoryid=921197 一.新建web工程,导入jasperreports所需的jar包,配置web.xml <serv ...

  8. ueditor1.4.3jsp版成功上传图片后却回显不出来与在线管理显示不出图片的解决方案

    这是因为路径问题,可以在jsp/config.json这个文件去改路径 通过“imageUrlPrefix”与“imagePathFormat”这两个属性去拼凑路径. “imageUrlPrefix” ...

  9. [xdoj1029]求解某个数的最高位和最低位

    解题关键: 1.最高位求法 long long int x=n^m; 式子两边同时取lg lg(x)=m*lg(n): x=10^(m*lg(n)): 10的整数次方的最高位一定是1,所以x的最高位取 ...

  10. ubuntu 下minicom超级终端的使用方法

    http://blog.chinaunix.net/uid-25909619-id-3184639.html Ubuntu下使用sshfs挂载远程目录到本地 http://blog.csdn.net/ ...