The All-purpose Zero

Problem Description
?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increasing (strictly) subsequence he can get.
Input
The first line contains an interger T,denoting the number of the test cases.(T <= 10)
For each case,the first line contains an interger n,which is the length of the array s.
The next line contains n intergers separated by a single space, denote each number in S.
Output
For each test case, output one line containing “Case #x: y”(without quotes), where x is the test case number(starting from 1) and y is the length of the longest increasing subsequence he can get.
Sample Input
2 7 2 0 2 1 2 0 5 6 1 2 3 3 0 0
Sample Output
Case #1: 5 Case #2: 5

Hint

In the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.

题意:求最长上升子序列,0可以变成任意数。
题解:LIS变形,一直没想到怎么处理中间的0,其实可以先去掉0,求出上升子序列,然后加上0的个数lower_bound(s,t,val),返回第一个大于等于val的数的位置,upper_bound(s,t,val)返回第一个大于val的数的位置,两者相减可以得到序列中k的个数。
#include<cstdio>
#include<algorithm>
#define INF 0x3f3f3f3f
#define M 100100
using namespace std;int s[M];int dp[M];
int main(){int t,n,i,sum,ans;int cas=1;scanf ("%d",&t);while (t--){sum=0;ans=0;scanf ("%d",&n);for (i=0;i<n;i++){scanf ("%d",&s[i]);}fill(dp,dp+n,INF);for (i=0;i<n;i++){if (s[i]==0){ans++;}else*lower_bound(dp,dp+n,s[i]-ans)=s[i]-ans;//去除0}sum=lower_bound(dp,dp+n,INF)-dp;sort (s,s+n);sum+=upper_bound(s,s+n,0)-lower_bound(s,s+n,0);//可以直接sum+=ans;printf ("Case #%d: %d\n",cas++,sum);}return 0;
}

hdu 5773 (The All-purpose Zero)相关推荐

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

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

  2. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  3. hdu 4389 囧,打表

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 :一个数能被他各个位数之和整除则符合要求,给L,R,问区间里有多少个数符合要求. 囧,居然打表就能过 ...

  4. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  5. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

  6. HDU 1248 寒冰王座(全然背包:入门题)

    HDU 1248 寒冰王座(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1248 题意: 不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票 ...

  7. hdu 1312 Red and Black 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 第二条深搜,题目并不难,但是做了我好久好久,由于一个细节,让我赌上了一个晚上的时间. 题目大意: ...

  8. HDU 1429 胜利大逃亡(续) (BFS+位压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  9. hdu 1272 小希的迷宫

    Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该 ...

  10. HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU

    MiYu原创, 转帖请注明 : 转载自 ______________白白の屋   题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1157 题目描述: ...

最新文章

  1. 李洪强iOS开发之RunLoop的原理和核心机制
  2. VR游戏制作中“延迟”的优化方法
  3. [js] innerHTML有什么缺点?
  4. webServlet(/) 和 webServlet(/*) 的区别
  5. 安装CentOS 6/7
  6. Focal Loss 和 LightGBM 多分类应用-python实现
  7. 网络游戏植入广告的案例
  8. favicon 尺寸问题
  9. 内华达大学里诺校区计算机科学,PayScal公布美国各州就业工资最高大学!加州第1竟是文理学院,纽约州也非哥大和纽大...
  10. JavaScript统计图表插件 Echarts
  11. 使用Apache poi生成excel并绘制折线统计图,扇形统计图
  12. 解决人人商城无法退款的问题
  13. 抖音壁纸小程序源码最新版,支持达人入驻和多端发布
  14. Java-Web总结03
  15. eel+python 开发html5跨平台桌面应用1
  16. Altium Designer 20 超全终极封装库
  17. 安卓修改服务器数据库,安卓端使用服务器端数据库
  18. ^[A-Za-z\\d]*$ 正则表达式
  19. 示例:Linux应用程序遍历当前系统的PCI设备
  20. cfa的pv怎么用计算机算,cfa计算器 算pv

热门文章

  1. CSS盒模型之内边距、边框、外边距 十九问(持续更新)
  2. 程序员值得收藏的41个电子书搜索网站
  3. WEB服务器硬件配置要求
  4. 百度API查询经纬度小页面
  5. 第九周上机项目3:个人所得税计算器
  6. 【小强推歌】---奥斯卡金曲MP3[下载]
  7. 计算机毕业设计ssm线上学习系统8e88w系统+程序+源码+lw+远程部署
  8. 服务器的正向代理与反向代理
  9. X86 CPU 漏洞 Meltdown 原理及google攻击代码
  10. 【中国数据创新琅琊榜】萨纳斯大数据实验室,高校大数据教学、实训、人才培养的最佳选择!