hdu 5256 LIS变形
来源:互联网 发布:淘宝手机端自定义模块 编辑:程序博客网 时间:2024/05/16 13:00
题目:
序列变换
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2129 Accepted Submission(s): 722
Problem Description
我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
请输出最少需要修改多少个元素。
请输出最少需要修改多少个元素。
Input
第一行输入一个T(1≤T≤10) ,表示有多少组数据
每一组数据:
第一行输入一个N(1≤N≤105) ,表示数列的长度
第二行输入N个数A1,A2,...,An 。
每一个数列中的元素都是正整数而且不超过106 。
每一组数据:
第一行输入一个
第二行输入N个数
每一个数列中的元素都是正整数而且不超过
Output
对于每组数据,先输出一行
Case #i:
然后输出最少需要修改多少个元素。
Case #i:
然后输出最少需要修改多少个元素。
Sample Input
221 1032 5 4
Sample Output
Case #1:0Case #2:1
分析:
一开始以为只需要求出最长上升子序列长度ans,答案即为n-ans
后来发现这种情况是会出错的 1 2 3 0 4 5 按照上面的做法会输出1 但0改成4之后1 2 3 4 4 5 并不是严格递增的
处理这种情况的方法是将序列中的a[i] 变成a[i]-i之后求ans=最长不降子序列的长度 答案为n-ans
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>typedef long long LL;using namespace std;const int N=1e5+10;const int inf=0x7f7f7f7f;int t,n,k,s;int a[N],dp[N];int lis(){memset(dp,inf,sizeof(dp));for(int i=1;i<=n;++i){*upper_bound(dp+1,dp+n+1,a[i])=a[i];///最长不降///*lower_bound(dp+1,dp+n+1,a[i])=a[i];///最长上升 }int res=lower_bound(dp+1,dp+n+1,inf)-(dp+1); return res;}int main(){scanf("%d",&t);for(int cas=1;cas<=t;++cas){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]-=i; int ans=lis();printf("Case #%d:\n%d\n",cas,n-ans);}return 0;}
阅读全文
1 0
- hdu 5256 LIS变形
- hdu 5256 序列变换 (LIS变形)
- HDU - 5256 序列变换 【LIS变形】
- hdu 5087(LIS变形)
- hdu 5734 LIS变形
- HDU 5141 LIS Again LIS变形+BIT
- HDU 5773 DP LIS变形
- HDU 5256 序列变换 (LIS变形&&STL)
- HDU 5256 序列变换 (DP/LIS变形)
- HDU 1069 Monkey and Banana LIS变形
- hdu 5489 Removed Interval LIS变形
- HDU 5489 Removed Interval (LIS,变形)
- hdu 1069 Monkey and Banana LIS变形
- HDU 1051 Wooden Sticks【LIS变形】
- hdu 5489 Removed Interval lis变形
- HDU 5125 Magic Balls DP(LIS变形)
- hdoj--5256--序列变换(lis变形)
- hdoj 5256 序列变换 【LIS 变形】
- NYOJ138
- 【Python3.6爬虫学习记录】(五)Cookie的使用以及简单的爬取知乎
- 设置图片圆角边框
- vue2.x---在vue2.x中,父组件怎么响应式向子组件传值,子组件怎么通过prop修改父组件数据?
- java之简单的回文算法
- hdu 5256 LIS变形
- JQuery
- C#控件之ImageList
- 接口自动化
- File文件递归复制
- redis---内部结构--skiplist
- 微信朋友圈能否吃掉微博?
- Java绘图基础代码
- Sliding Window