HDU5773(The All-purpose Zero LIS变形)
来源:互联网 发布:js调用打印机直接打印 编辑:程序博客网 时间:2024/06/05 06:26
题目链接
序列的0可以变为任意数,问LIS
0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,统计结果的时候再算上0的数量。为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的。
#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<string>#include<cmath>#include<map>#include<set>#include<cstdlib>#include<vector>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define LL long long#define pb push_back#define gcd __gcd#define For(i,j,k) for(int i=(j);i<k;i++)#define lowbit(i) (i&(-i))#define _(x) printf("%d\n",x)const int maxn = 2e5+200;const int inf = 1 << 28;int a[maxn];int d[maxn],g[maxn];int b[maxn];int c[maxn],vis[maxn];int main(){ int T;int cas=1; scanf("%d",&T); while(T--){ int n;scanf("%d",&n); int num = 0; int k=0;cl(vis,0); for(int i=0;i<n;i++){ scanf("%d",&a[i]);d[i]=0;g[i]=inf; b[i]=0; if(a[i]==0){num++;vis[i]=1;} if(a[i])b[i]=num; } g[n]=inf; //for(int i=0;i<n;i++)cout<<b[i]<<' ';cout<<endl; for(int i=0;i<n;i++)a[i]-=b[i]; for(int i=0;i<n;i++)if(!vis[i]){ c[k++]=a[i]; } int ans = 0; for(int i=0;i<k;i++){ int k = lower_bound(g+1,g+1+n,c[i])-g; d[i]=k; g[k]=c[i]; ans = max(ans, d[i]); } printf("Case #%d: %d\n",cas++,ans+num); } return 0;}
0 0
- hdu5773 The All-purpose Zero(LIS变形)
- HDU5773(The All-purpose Zero LIS变形)
- HDU5773 The All-purpose Zero(LIS变形)
- hdu5773-LIS&技巧-The All-purpose Zero
- hdu5773 The All-purpose Zero(DP)
- hdu5773 The All-purpose Zero
- HDU5773 The All-purpose Zero
- HDU5773:The All-purpose Zero
- The All-purpose Zero-HDU5773
- The All-purpose Zero||HDU5773
- HDU 5773 The All-purpose Zero ( LIS 变形 )
- 【HDU】-5773-The All-purpose Zero(LIS变形,思维)
- HDU 5773 The All-purpose Zero (LIS变形)
- (多校第四场1010)HDU5773 The All-purpose Zero(LIS)
- HDU-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变形】
- js的宽高度offsetWidth;clientWidth;
- 【杭电1242】广搜+队列
- nyoj16 矩形嵌套 排序+最长增长子序列
- 获得推送创建通知的相关内容
- 杭电2030解题代码
- HDU5773(The All-purpose Zero LIS变形)
- C++中可调用对象
- cadence学习2—cadence 如何拷贝别人图纸中的原件封装
- QingCloud Insight 2016:诠释云计算未来图景
- 欢迎使用CSDN-markdown编辑器
- 经典java面试题目
- Medoo的使用教程
- cts 测试中需要前置条件才能pass的fail项解决方案
- PyGobject(三十七)布局容器之Dialog