hdu5256: 序列变换
来源:互联网 发布:豫剧板胡网络培训班 编辑:程序博客网 时间:2024/06/03 09:56
题意:一个数列,a1,a2,a3,a4,…,an,需要最少修改多少个元素,使得这个序列严格递增?
a[i]-i 非递减序列 因为a[i] < a[i+1],且a[i],a[i+1]都是整数,所以有a[i+1]-1>=a[i],整理得a[i+1]-(i+1)>=a[i]-i。令b[i]=a[i]-i。则可以求出b[i]的最长不下降子序列的长度len,最后用n-len即为需要改变的最少的元素个数。
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<queue>using namespace std;int b[100010];int a[100010];int dp[100010];int main(void) { int t; scanf("%d",&t); int n; int cs = 1; while(t--){ scanf("%d",&n); for(int i = 0; i < n; i++){ scanf("%d",&a[i]); a[i] = a[i] - i; } int len = 1; b[0] = a[0]; for(int i = 1; i < n; i++){ if(a[i] >= b[len-1]) b[len++] = a[i]; int pos = upper_bound(b,b+len,a[i]) - b; b[pos] = a[i]; } printf("Case #%d:\n%d\n",cs++,n-len); } return 0;}
阅读全文
0 0
- HDU5256: 序列变换
- hdu5256 序列变换
- hdu5256: 序列变换
- hdu5256【序列变换】【LIS】
- hdu5256 序列变换 dp LIS
- hdu5256 序列变换 最长递增子序列
- hdu5256 序列变换(LIS模型)
- hdu5256序列变换(非递减子序列)
- HDU5256 序列变换(LIS求严格上升子序列)
- hdu5256 序列变换 百度之星初赛第二场 最长上升子序列变形
- hdu5256序列严格递增
- hdu5256序列变幻
- 序列变换
- 序列变换
- 序列变换
- 序列变换
- NOI 2009 变换序列
- [NOI2009]变换序列
- Java基于无向有权图实现克鲁斯卡尔算法
- 宝塔控制面板忘记密码怎么找回?
- 总结/抽象和封装
- 特征组合可以提高LR分类效果
- linux学习01
- hdu5256: 序列变换
- Linux系统分区和挂载浅谈
- Hive的基本语法
- swing界面编程-国际化-中英文切换-简单示例供参考
- BZOJ 1087 互不侵犯的国王 状态压缩dp
- PHP接口
- truntact 和 delete 的区别
- 开启cdn后无法显示字体图标——CDN服务器跨域问题
- 逻辑结构定义及其分类