大意: 给定序列, 每次操作可以任选一个数+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)的更多相关文章

  1. Codeforces 713C Sonya and Problem Wihtout a Legend(单调DP)

    [题目链接] http://codeforces.com/problemset/problem/713/C [题目大意] 给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 【CodeForces】713 C. Sonya and Problem Wihtout a Legend

    [题目]C. Sonya and Problem Wihtout a Legend [题意]给定n个数字,每次操作可以对一个数字±1,求最少操作次数使数列递增.n<=10^5. [算法]动态规划 ...

  6. Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend

    C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces 713C Sonya and Problem Wihtout a Legend(DP)

    题目链接   Sonya and Problem Wihtout a Legend 题意  给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成 ...

随机推荐

  1. Windows渗透利器之Pentest BOX使用详解(一)

    内容概览:                                     知识科普                                    优缺点总结 功能参数详解翻译: 控制 ...

  2. c# Castle Windsor简单例子

    Windsor是Castle的IOC框架.需要用到两个dll(Castle.Core.dll和Castle.Windsor.dll). 1.接口以及接口实现类: public interface IT ...

  3. java框架之SpringBoot(10)-启动流程及自定义starter

    启动流程 直接从 SpringBoot 程序入口的 run 方法看起: public static ConfigurableApplicationContext run(Object source, ...

  4. 使用maven搭建springMVC开发环境

    1.引入框架所需的包,pom.xml文件中添加如下配置: <dependency> <groupId>org.springframework</groupId> & ...

  5. AdPlus

    adplus是windbg下面附带的一个小工具: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/adplus A ...

  6. 解决mysql大小写敏感问题

    先在服务中 找到 my.min 文件 在 [mysqld] 下面添加一行: lower_case_table_names = 0 其中 0:区分大小写,1:不区分大小写 设置好后 需要重启服务   然 ...

  7. js跨域交互之jsonp - 看完就能让你了解jsonp原理 (原)

    跨域? 跨域的安全限制都是对浏览器端来说的,服务器端是不存在跨域安全限制的. 同源策略? 一般来说 a.com 的网页无法直接与 b.com的服务器沟通, 浏览器的同源策略限制从一个源加载的文档或脚本 ...

  8. supervisor 守护进程

    一.supervisor 安装 1.yum -y install epel-release 2.yum -y install supervisor 二.supervisor 配置文件详解 三.supe ...

  9. 20190404用户及用户组管理(week1_day4)

    useradd userdel usermod groupadd groupdel 用户管理 为什么需要有用户? 1. linux是一个多用户系统 2. 权限管理(权限最小化) 用户:存在的目录是为了 ...

  10. 给datagrid的日期格式化成年月日

    $('#infos').datagrid({ title:'系统版本列表', iconCls:'icon-view', method:'POST', singleSelect:false, fit : ...