對於不嚴格單調的我們可以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. 配置composer代理

    composer config -g repo.packagist composer https://packagist.phpcomposer.com

  2. [RK3288][Android6.0] 调试笔记 --- 移除uboot和kernel开机logo【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/71600690 Platform: RockchipOS: Android 6.0Kernel ...

  3. linuxshell,闲散命令记录

    1. 移动光标到 0:0 位置 printf "\033[0;0H" 2. 清屏 printf "\033[2J" 3. awk接收 外部变量 awk -v v ...

  4. SVG-Android开源库——SVG生成Vector资源文件的编辑预览工具

    Vector矢量图在Android项目中的应用越来越广泛,但是如果你想用Android Studio自带的工具将SVG图片转化成Vector资源文件却是相当麻烦,首先能支持的SVG规范较少,其次操作流 ...

  5. certificate unknown(46) - 中间证书问题排查

    因为腾讯云的网站备案迟迟没有批下来,因此使用了朋友在阿里云的域名yk,我则申请了一台阿里云服务器,并将域名解析映射至该服务器.SSL证书则是在腾讯云上申请的,使用了Apache文件夹中的文件,放置在c ...

  6. Messes in Reading Source Coding of SSD

    这里记录在学习SSD源码过程中用到的相关内容 keras.applications.imagenet_utils.preprocess_input(): 用来将读入的原始图片张量转换成为需要Image ...

  7. Linux vSphere SDK for Perl 执行脚本报错

      本人在gentoo系统上安装完vSphere for Perl之后,执行/usr/lib/vmware-viperl/app/vm/vminfo.pl脚本. 提示错误如下: Server vers ...

  8. tcpdump 探测器分析

    注:默认情况下,tcpdump临听它遇见的第一个网络接口,如果它选择了错误的接口,可以-i标志强行指定接口,如果DNS不能用,或者只是不希望tcpdump进行名字查找,请使用-n选项,这个选项(-n) ...

  9. bzoj 2155 Xor

    题目大意: 求一条从$1 \rightarrow n$的路径是异或和最大 思路: 先随便求一棵生成树,然后求出所有环,对于所有环都可以去转一圈只取到这个环的贡献 那么就是线性基裸题了 #include ...

  10. C++之输入输出流和文件传输流

    1.流的控制 iomanip          在使用格式化I/O时应包含此头文件.    stdiostream   用于混合使用C和C + +的I/O机制时,例如想将C程序转变为C++程序 2.类 ...