hdu 5256 序列变换 -LIS 严格转非严格
来源:互联网 发布:分时量比曲线源码 编辑:程序博客网 时间:2024/06/06 00:12
http://acm.hdu.edu.cn/showproblem.php?pid=5256
我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
请输出最少需要修改多少个元素。
请输出最少需要修改多少个元素。
N<=1e5
如果是严格递增的话,是不太好处理的,如果换成非严格递增的话,我们只需要求一遍非严格的lis,然后n-maxlen就是答案了
如果把一个求严格递增的序列转换为非严格递增的序列呢?
推导过程大致如下:a[i] < a[i+1] ——> a[i] <= a[i+1]-1 ——> a[i]-i <= a[i+1]-(i+1)——> b[i]<=b[i+1]
也就是令b[i]=a[i]-i就可以了。
城市套路多
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>using namespace std;const int maxn = 100010;int arr[maxn],ans[maxn];int main(){ //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int t; int cnt=1; cin>>t; while(t--) { int n,idx=0; scanf("%d",&n); for (int i=1; i<=n; i++) { int x; scanf("%d",&x); arr[++idx]=x-i; } n=idx; //memset(ans,0,sizeof(ans)); ans[1] = arr[1]; int len=0; if (n>=1) len=1; for(int i=2; i<=n; ++i) { if(arr[i]>=ans[len]) //*****fei严格 ans[++len]=arr[i]; else { int pos=upper_bound(ans+1,ans+len+1,arr[i])-ans;//****ei严格 ans[pos] = arr[i]; } } printf("Case #%d:\n%d\n",cnt++,n-len); } return 0;}
0 0
- hdu 5256 序列变换 -LIS 严格转非严格
- HDU5256 序列变换(LIS求严格上升子序列)
- 【LIS】【严格递增和非严格递增】
- LIS 最长严格上升子序列问题
- HDU-5256 序列变换(LIS)
- hdu 5256 序列变换 (LIS变形)
- HDU - 5256 序列变换 (LIS转化)
- 【HDU】5256 - 序列变换(LIS)
- HDU 5256 (序列变换 LIS)
- HDU - 5256 序列变换 【LIS变形】
- hdu 1025 最长严格上升子序列
- 简单dp hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
- hdu5256序列严格递增
- 1020 -- 严格递增序列
- 最长递增子序列(poj-3903,1631我,1887(严格下降),2533(严格上升),LIS)
- HDU 5256 序列变换 (LIS变形&&STL)
- hdu 5256 序列变换 LIS 变型 思维转化
- HDU 5256 序列变换 (DP/LIS变形)
- andorid 自定义View 命名空间 长话短说
- iOS 制作圆形图片
- 双向循环链表——STL迭代器
- iOS10适配问题
- [LeetCode] 166. Fraction to Recurring Decimal
- hdu 5256 序列变换 -LIS 严格转非严格
- 【Easy】206. Reverse Linked List
- 微信公众号测试号申请及访问
- 404错误解决新思路
- Rabbitmq 流控
- 写个脚本生成库链接
- ubuntu16.04(2) -中文输入问题
- POJ 1886简单模拟
- iOS Design