【bzoj4282】慎二的随机数列
2017-10-20 20:58
169 查看
Description
间桐慎二是间桐家著名的废柴,有一天,他在学校随机了一组随机数列, 准
备使用他那强大的人工智能求出其最长上升子序列,但是天有不测风云,人有旦
夕祸福,柳洞一成路过时把间桐慎二的水杯打翻了……
现在给你一个长度为 n 的整数序列,其中有一些数已经模糊不清了,现在请
你任意确定这些整数的值,使得最长上升子序列最长(为何最长呢?因为间桐慎
二向来对自己的人品很有信心) 。
Input
第一行一个正整数 n。
接下来 n 行,第 i 行若为“K x” ,则表示第 i 个数可以辨认且这个数为 x;
若为“N” ,则表示第i 个数已经辨认不清了。
Output
第一行一个整数,表示最长的最长上升子序列长度。
Sample Input
4
K 1
N
K 2
K 3
Sample Output
3
HINT
对于100%的数据,n ≤ 100000,|x| ≤ 10^9
题解
不知道的数一定可以出现在序列里
每个数减去之前出现过的不知道的数的个数
做LIS
答案加不知道数的个数
代码
间桐慎二是间桐家著名的废柴,有一天,他在学校随机了一组随机数列, 准
备使用他那强大的人工智能求出其最长上升子序列,但是天有不测风云,人有旦
夕祸福,柳洞一成路过时把间桐慎二的水杯打翻了……
现在给你一个长度为 n 的整数序列,其中有一些数已经模糊不清了,现在请
你任意确定这些整数的值,使得最长上升子序列最长(为何最长呢?因为间桐慎
二向来对自己的人品很有信心) 。
Input
第一行一个正整数 n。
接下来 n 行,第 i 行若为“K x” ,则表示第 i 个数可以辨认且这个数为 x;
若为“N” ,则表示第i 个数已经辨认不清了。
Output
第一行一个整数,表示最长的最长上升子序列长度。
Sample Input
4
K 1
N
K 2
K 3
Sample Output
3
HINT
对于100%的数据,n ≤ 100000,|x| ≤ 10^9
题解
不知道的数一定可以出现在序列里
每个数减去之前出现过的不知道的数的个数
做LIS
答案加不知道数的个数
代码
#include<bits/stdc++.h> #define mod 1000000007 #define inf 1000000005 #define pa pair<int,int> typedef long long ll; using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,sum,ans,a[100005],q[100005],tot; char ch[5]; int main() { n=read(); for (int i=1;i<=n;i++) { scanf("%s",ch); if (ch[0]=='K')a[++tot]=read()-sum; else sum++; } for (int i=1;i<=tot;i++) { int l=0,r=ans; while (l!=r) { int mid=(l+r+1)>>1; if (a[q[mid]]<a[i]) l=mid;else r=mid-1; } l++; ans=max(ans,l); q[l]=i; } cout<<ans+sum; return 0; }
相关文章推荐
- BZOJ 4282 慎二的随机数列 LIS
- 【bzoj4282】【慎二的随机数列】【dp】
- BZOJ4282 : 慎二的随机数列
- bzoj 4282: 慎二的随机数列
- bzoj 4282: 慎二的随机数列 最长不下降序列
- [BZOJ5427]最长上升子序列/[BZOJ4282]慎二的随机数列
- 【BZOJ4282】慎二的随机数列 乱搞
- 【BZOJ4282】慎二的随机数列(LIS)
- BZOJ 4282: 慎二的随机数列|动态规划
- [bzoj4282]慎二的随机数列_动态规划_贪心
- 【bzoj4282】慎二的随机数列
- BZOJ 4282 慎二的随机数列 动态规划
- [bzoj4282]慎二的随机数列
- BZOJ4282: 慎二的随机数列
- 4282: 慎二的随机数列 DP
- BZOJ 4287(慎二的随机数列-构造+LIS)
- JZOJ 3693. 【NOI2014模拟6.20】慎二的随机数列
- 【JZOJ 3693】慎二的随机数列(seq)
- [DP LIS] BZOJ 4282 慎二的随机数列
- 【BZOJ4282】慎二的随机数列