HDU 5773 The All-purpose Zero 第四场多校赛 LIS变形(最长上升子序列)
来源:互联网 发布:阿里云ecs sn型号 编辑:程序博客网 时间:2024/05/19 03:25
点击打开链接
题意是:
给你一个长度为10W的数组,每个数范围0-100W
其中的0可以变为INT范围内的任意值
问最长上升子序列的长度
思路:
0可以转化成任意整数,包括负数,
显然求LIS时尽量把0都放进去必定是正确的。
因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,
统计结果 的时候再算上0的数量。
(因为本来是应该使dp[len+1]=dp[len]+1,并且其他的值也会相应的改变,但是这样不好算, 所以我们就倒着来)
为了保证严格递增,
我们可以将每个权值S[i]减去i前面0的个数,
再做LIS,就能保证结果是严格递增的
#include<iostream>#include<cstring>#include<map>#include<cstdio>#include<cmath>#include<queue>#include<algorithm>#include<stack>#define mod 19999#define INF 0x3f3f3f3f#define bug puts("***********")using namespace std;int dp[1000000];int main(){ int n,m,t,x,cas=0; scanf("%d",&t); int num=0; while(t--){ int cnt=0,num=0; dp[0]=-INF; ///会出现 000000000000000 1 的情况 所以必须将 a[0] 变成最小值 scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&x); if(!x) num++; else { x=x-num; if(dp[cnt]<x){ dp[++cnt]=x; } else{ int pos=lower_bound(dp+1,dp+cnt+1,x)-dp; if(dp[pos]>x){ dp[pos]=x; } } } } printf("Case #%d: %d\n",++cas,cnt+num); } return 0;}
0 0
- HDU 5773 The All-purpose Zero 第四场多校赛 LIS变形(最长上升子序列)
- HDU 5773 The All-purpose Zero(最长上升子序列)
- HDU 5773 The All-purpose Zero ( LIS 变形 )
- 【HDU】-5773-The All-purpose Zero(LIS变形,思维)
- HDU 5773 The All-purpose Zero (LIS变形)
- HDU 5773 The All-purpose Zero (DP最长上升子序列)
- HDU-5773-The All-purpose Zero-最长上升子序列改写
- 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero
- (HDU 5773)The All-purpose Zero <最长上升子序列 + 思维题> 多校训练4
- hdu5773 The All-purpose Zero 贪心+最长上升子序列
- Hdu-5773 The All-purpose Zero(LIS变形)
- HDU 5773 The All-purpose Zero【LIS变形】
- HDU 5773 The All-purpose Zero【LIS变形】
- HDU-5773 The All-purpose Zero(LIS变形)
- 最长递增子序列 ( LIS )——The All-purpose Zero ( HDU 5773 ) ( 2016 Multi-University Training Contest 4 1010 )
- HDU 5773 The All-purpose Zero lis
- hdu 5773 The All-purpose Zero (LIS)
- HDU-The All-purpose Zero(LIS)
- leetcode No55. Jump Game
- linux source 解析
- Android 第二章
- impossible的真正含义
- Android webview上传图片(适配3.0,4.0,5.0,6.0)
- HDU 5773 The All-purpose Zero 第四场多校赛 LIS变形(最长上升子序列)
- Python 函数作用域
- JAVA输入输出流
- Hadoop:HDFS的健壮性设计
- jQuery—常规选择器
- Java基础学习总结(44)——10个Java 8 Lambda表达式经典示例
- [文章摘要] CourtVision: New Visual and Spatial Analytics for the NBA
- hdu 5616 Jam's balance(简单dp)
- 超便捷的日报填写与查阅,你的公司必然需要!