HDU 5773 The All-purpose Zero(贪心LIS)
来源:互联网 发布:全境封锁购买 知乎 编辑:程序博客网 时间:2024/05/16 10:20
http://acm.hdu.edu.cn/showproblem.php?pid=5773
给你一串数字,里面0可以变成其他数字,问你变化之后LIS的长度
这题首先要发现,选0肯定比选别的更优,所以我们可以把0都去掉,在没有0的情况下,考虑选几个数字,然后如果对于ai和aj,他们俩要选,他们的差值应该大于他们俩之间0的个数,所以我们可以记录sumi表示到i为止,0的个数,然后对于没有0的数组,要选上升的话必须满足
这个姿势很不错,以后碰到LIS需要想到
代码
#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define MAX 100005#define MAXN 1000005#define maxnode 205#define sigma_size 26#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define pii pair<int,int>#define bits(a) __builtin_popcount(a)#define mk make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-4;const LL mod = 1e9+7;const ull mx = 133333331;/*****************************************************/inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; }/*****************************************************/vector<int> v;int st[MAX];int main(){ //freopen("in.txt","r",stdin); int t,kase=0; scanf("%d",&t); while(t--){ int n; cin>>n; v.clear(); int num=0; for(int i=0;i<n;i++){ int a; scanf("%d",&a); if(a==0) num++; else v.push_back(a-num); } int top=0; for(int i=0;i<v.size();i++){ if(top==0||v[i]>st[top-1]) st[top++]=v[i]; else{ int pos=lower_bound(st,st+top,v[i])-st; st[pos]=v[i]; } } kase++; printf("Case #%d: %d\n",kase,top+num); } return 0;}
0 0
- HDU 5773 The All-purpose Zero(贪心LIS)
- HDU 5773 The All-purpose Zero(LIS+贪心思维)
- HDU 5773 The All-purpose Zero DP,贪心,LIS
- HDU 5773 The All-purpose Zero lis
- hdu 5773 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)
- HDU 5773 The All-purpose Zero ( LIS 变形 )
- hdu 5773 The All-purpose Zero 思维转化+nlogn LIS
- HDU 5773 The All-purpose Zero(LIS)
- HDU Problem 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变形)
- HDU 5773 The All-purpose Zero【LIS变形】
- HDU 5773 The All-purpose Zero【LIS变形】
- 华为[编程题]最高分是多少
- HDU 2845 Beans (最大不连续子序列和)(压缩求解)
- 修改IOS UITableViewCell箭头颜色方法
- Android Studio 开发中的一个小功能 使用TextView搜索ListView
- Bash学习
- HDU 5773 The All-purpose Zero(贪心LIS)
- 微信 显示通讯录的代码
- 论integer是地址传递还是值传递
- Android 同心圆的遥控器的自定义
- redis限制注意点
- 企业邮箱Postfix运维
- 浅谈HashSet
- Python黑帽编程 2.0 第二章概述
- vb.net 关闭所有已经打开的窗体 包括启动窗体