對於不嚴格單調的我們可以n^2DP,首先每個數一定在原數組中出現過,如果沒出現過不如減小到出現過的那個花費更小,效果相同

所以f[i][j]表示把i改到離散化后j的最小代價,每次維護前一狀態最小值mn再加上這次的值就是答案

圖像沒看懂:https://blog.csdn.net/lycheng1215/article/details/80089004

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
const ll inf=1e18+;
int n,a[maxn],b[maxn];
ll f[maxn][maxn],mn[maxn];
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll abs(ll a){return a<?-a:a;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]),a[i]-=i,b[i]=a[i];
sort(b+,b++n);
int bb=unique(b+,b++n)-b-; for(int i=;i<=n;i++){
ll mn=inf;
for(int j=;j<=bb;j++){
mn=min(mn,f[i-][j]);
f[i][j]=abs(b[j]-a[i])+mn;
}
}
ll ans=inf;
for(int i=;i<=bb;i++)
ans=min(ans,f[n][i]);
printf("%lld\n",ans); }

[題解](DP)CF713C_Sonya and Problem Wihtout a Legend的更多相关文章

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

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

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

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

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

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

  6. 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend

    //把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...

  7. Sonya and Problem Wihtout a Legend

    Sonya and Problem Wihtout a Legend Sonya was unable to think of a story for this problem, so here co ...

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

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

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

随机推荐

  1. java 浮点数

    package precisenumber; //import java.util.*;public class PreciseNumber { public int fore; public int ...

  2. BAT网络运维常见面试题目总结

    BAT常见面试题目总结 Author:Danbo 2015-7-11 TCP/IP详解鸟哥Linux的书网络安全ping的原理make的过程文件有哪些类型各种Linux发行版的区别.有关suid的作用 ...

  3. Vue实战指南之依赖注入(provide / inject)

    案例 UI美眉说咱家的选项菜单太丑了,小哥哥能不能美化一下呀,洒家自然是说小意思啦~自定义一个select组件,so easy~ 简单粗暴型: <el-select v-model=" ...

  4. haproxy参数解析

    HAProxy工作于隧道模式,其仅检查每一个连接的第一个请求, 1. option abortonclose #当服务器负载过高时,将自动关闭队列中处理时间较长的连接请求 2. option http ...

  5. 对xml文件的sax解析(增删改查)之一

    crud(增删改查): c:creat r:retrieve u:update d:delete 以下笔记来自于韩顺平老师的讲解. 现在是用java来操作. 第一步:新建java工程.file-new ...

  6. SQL Server中数据类型对应C#中数据类型

    在SQL Server 2008中新建数据表的时候有33种数据类型可选,下面分别列举了这些类型对应的C#数据类型 //----------------------------------------- ...

  7. 限制远程桌面登录IP的方法

    转自:http://www.cnblogs.com/vaexi/articles/2106623.html 限制远程桌面登录IP的方法 第一种方法: 1.打开Windows自带的防火墙2.开放允许例外 ...

  8. 上传图片 ajax input type="file" 兼容 ie chroem 火狐

    上传图片,转载请注明出处!!! 兼容 ie chroem 火狐 html: <div id="uploadForm"> <input id="file& ...

  9. awk实现求和、平均、最大值和最小值的计算操作

    0.准备和数据文件 比如有一个数据文件,只有一列(在之前可以通过各种手段过滤出只有数字这一列),比如操作的响应时间 Txt代码  490898  1189235  20212  1494270  14 ...

  10. python中的linspace,meshgrid,concatenate函数

    linspace可以用来实现相同间隔的采样. numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) ...