Sonya and Problem Wihtout a Legend CodeForces - 714E (dp)
大意: 给定序列, 每次操作可以任选一个数+1/-1, 求最少操作数使序列严格递增.
序列全-i后转化为求最少操作数使序列非降, 那么贪心可以知道最后$a_i$一定是修改为某一个$a_j$了, 暴力dp即可.
#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
typedef long long ll;
const int N = 3e3+10;
int n, a[N], b[N];
ll dp[N][N]; int main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i),a[i]-=i,b[i]=a[i];
sort(b+1,b+1+n);
REP(i,1,n) dp[i][0]=1e18;
REP(i,1,n) REP(j,1,n) dp[i][j]=min(dp[i][j-1],dp[i-1][j]+abs(a[i]-b[j]));
printf("%lld\n", dp[n][n]);
}
Sonya and Problem Wihtout a Legend CodeForces - 714E (dp)的更多相关文章
- Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)
[题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)
题目链接: C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 ...
- 【CodeForces】713 C. Sonya and Problem Wihtout a Legend
[题目]C. Sonya and Problem Wihtout a Legend [题意]给定n个数字,每次操作可以对一个数字±1,求最少操作次数使数列递增.n<=10^5. [算法]动态规划 ...
- Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend
C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...
- Codeforces 713C Sonya and Problem Wihtout a Legend DP
C. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)(将一个数组变成严格单增数组的最少步骤)
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(DP)
题目链接 Sonya and Problem Wihtout a Legend 题意 给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成 ...
随机推荐
- UIScrollView上面的UIButton点击始终在中间
-(void)btnClick:(IdleTopChoseBtn *)btn{ btn.selected = YES; _choseBtn.selected = NO; _choseBtn = btn ...
- oracle_18c新建用户用normal登陆失败
工具介绍:win10系统,使用的是oracle18c. 首先说一下oracle18c的特性,在oracle18c创建用户要以c##开头,比如: --创建新用户create user c##test_u ...
- JAVA基础——集合——HashMap
HashMap集合: 常用方法(JDK1.8): 从此映射中移除所有映射关系(元素): public void clear() 返回此 HashMap 实例的浅表副本:并不复制键和值本身: p ...
- Intellij Idea debug 模式如果发现异常,即添加异常断点在发生异常处
以前用eclipse的时候,可以根据所抛出的异常进行调试,比如:出现了空指针异常,我想知道是哪一行抛出的,在eclipse中我只需在debug模式下把空指针异常这个名字设置进去,当遇到空指针异常时,e ...
- Tensorflow之调试(Debug)及打印变量
参考资料:https://wookayin.github.io/tensorflow-talk-debugging 几种常用方法: 1.通过Session.run()获取变量的值 2.利用Tensor ...
- Cocos Creator 使用计时器(官方文档摘录)
在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...
- C语言进阶之路(二)----字符串操作常见模型
1.while模型 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #includ ...
- C# Remoting例子
4-23 https://www.cnblogs.com/zhengyun_ustc/archive/2006/06/09/remoting_InvalidCredentialException.ht ...
- Linux基础培训知识点汇总
一.Linux简介1.Linux操作系统诞生于1991年10月5日,由林纳斯·托瓦兹在comp.os.minix新闻组上发布消息,正式向外宣布Linux内核的诞生.2.Linux同时也衍生了很多版本( ...
- 微信小程序上传与下载文件
需要准备的工作: ①.建立微信小程序工程,编写以下代码. ②.通过IDE建立springboot+web工程,编写接收文件以及提供下载文件的方式,并将上传的文件相关信息记录在mysql数据库中.具体请 ...