HDU 5773 The All-purpose Zero 脑洞LIS
给定一个序列,里面的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的更多相关文章
- hdu 5773 The All-purpose Zero 最长上升子序列+树状数组
题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...
- 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)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773 0可以改变成任何数,问你严格递增的子序列最长是多少. 猜测0一定在最长上升子序列中用到,比如2 ...
- 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 线段树 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 5773 The All-purpose Zero(树状数组)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5773 [题目大意] 给出一个非负整数序列,其中的0可以替换成任意整数,问替换后的最长严格上升序列长 ...
- HDU 1087 最长不下降子序列 LIS DP
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...
随机推荐
- navicat导入sql文件
Hello,大家好.Navicat是我们平时使用较多的一个数据库客户端工具,平时小天我主要是用来连接mysql的,使用的时候还是很方便的. 今天小天我就给大家分享一个Navicat如何导入导出sql文 ...
- IP 地址漂移
1.概念 应用访问虚拟ip,当主服务器正常工作时,虚拟ip指向主服务器,当主服务器宕掉后,虚拟ip自动指向从服务器,当主服务器被人修好后,再自动指向主服务器, 这种虚拟ip的指向方式称为ip地址漂移. ...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...
- Canal入门
配置mysql 1.mysql开启binlog mysql默认没有开启binlog,修改mysql的my.cnf文件,添加如下配置,注意binlog-format必须为row,因为binlog如果为S ...
- linux下dns设置详解
DNS就是Domain Name System,它能够把形如www.21php.com这样的域名转换为211.152.50.35这样的IP地址;没有DNS,浏览21php.com这个网站时,就必须用2 ...
- Code:目录
ylbtech-Code:目录 1.返回顶部 1. https://github.com/ 2.返回顶部 1. https://gitee.com 2. 3.返回顶部 4.返回顶部 5.返 ...
- java基础知识学习 java异常
1: Unchecked Exception( 也就是运行时异常) VS Check Exception(非运行时异常) 2: 运行期异常 VS 非运行期异常? 非运行时异常: 必须在代码中显示 ...
- 一 vue开发环境搭建
2016年,Vue同Angular.React形成三足鼎立的局面,让前端的开发者顾不暇接,今天我们就来了解一下Vue的环境搭建. 一.node.js安装: node.js:一种javascript的运 ...
- lvs-nat搭建httpd
拓扑图: #172.16.252.10 [root@~ localhost]#route -n Kernel IP routing table Destination Gateway Genmask ...
- 问题:C#调webservice超时;结果:C#调用webservice服务超时
C#调用WebService服务时,报错,The operation has timed out,意思是“操作超时”. 方法/步骤 首先修改服务端配置 WebService服务所在站点为服务端,它提供 ...