题意:给你一个数列,对于每个数字你都可以++或者−− 
然后花费就是你修改后和原数字的差值,然后问你修改成一个严格递增的,最小花费

思路:很久以前做过一道一模一样的

严格递增很难处理,就转化为非严格递增处理

设a[i]<a[j],i<j

a[j]-a[i]>=j-i

a[j]-j>=a[i]-i

即将a[i]转化为a[i]-i处理

非严格递增情况下最终数列一定是由原先的数组成的,不可能出现某两个原数中间的值

dp[i,j]为第i位,结尾为第j大的数,转化成这样的数列的最小费用

dp[i,j]=min(dp[i-1,k]+abs(a[i]-b[j])) k<=j

第一项用前缀和优化

 const oo=;
var dp,f:array[..,..]of int64;
a,b:array[..]of longint;
n,i,j:longint;
ans:int64; function min(x,y:int64):int64;
begin
if x<y then exit(x);
exit(y);
end; procedure qsort(l,r:longint);
var i,j,t,mid:longint;
begin
i:=l; j:=r; mid:=b[(l+r)>>];
repeat
while mid>b[i] do inc(i);
while mid<b[j] do dec(j);
if i<=j then
begin
t:=b[i]; b[i]:=b[j]; b[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end; begin
//assign(input,'1.in'); reset(input);
// assign(output,'1.out'); rewrite(output);
readln(n);
for i:= to n do
begin
read(a[i]);
a[i]:=a[i]-i;
end;
b:=a;
qsort(,n);
for i:= to n do
begin
for j:= to n do f[i,j]:=oo;
for j:= to n do
begin
dp[i,j]:=abs(a[i]-b[j])+f[i-,j];
f[i,j]:=min(f[i,j-],dp[i,j]);
end;
end;
ans:=oo;
for i:= to n do ans:=min(ans,dp[n,i]);
writeln(ans);
//close(input);
// close(output);
end.

【CF713C】Sonya and Problem Wihtout a Legend(离散化,DP)的更多相关文章

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

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

  2. CF713C Sonya and Problem Wihtout a Legend & hihocoder1942 单调序列

    这两个题是一样的,不过数据范围不同. 思路1: 在CF713C中,首先考虑使生成序列单调不下降的情况如何求解.因为单调上升的情况可以通过预处理将a[i]减去i转化成单调不下降的情况. 首先,生成的序列 ...

  3. CF713C Sonya and Problem Wihtout a Legend

    考虑我们直接选择一个暴力\(dp\). \(f_{i,j} = min_{k<=j}\ (f_{i - 1,k}) + |a_i - j|\) 我们考虑到我们直接维护在整个数域上\(min(f_ ...

  4. Codeforces713C Sonya and Problem Wihtout a Legend(DP)

    题目 Source http://codeforces.com/problemset/problem/713/C Description Sonya was unable to think of a ...

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

    Description Sonya was unable to think of a story for this problem, so here comes the formal descript ...

  6. codeforces C. Sonya and Problem Wihtout a Legend(dp or 思维)

    题目链接:http://codeforces.com/contest/713/problem/C 题解:这题也算是挺经典的题目了,这里附上3种解法优化程度层层递进,还有这里a[i]-i<=a[i ...

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

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

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

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

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

随机推荐

  1. cocos2x (c++/lua) spine 文件的预加载

    在之前,笔者写过一编博客,通过lua在加载场景加载spineAnimation动画精灵,保存在table中,然后在游戏中创建动画精灵时,提取加载好的spineAnimaiton中的 spSkeleto ...

  2. 一句话懂什么是JS闭包

    无论何时声明新函数并将其赋值给变量,都要存储函数定义和闭包.闭包包含在函数创建时作用域中的所有变量,它类似于背包.函数定义附带一个小背包,它的包中存储了函数定义创建时作用域中的所有变量. 我将永远记住 ...

  3. centos6启动故障排除

    centos6中boot文件被全部删除的故障排除 /boot文件里关于启动的核心文件有三个,/vmlinuz-2.6.32-696.e16.x86_64,initramfs-2.6.32-696.el ...

  4. python3 连接 mysql和mariadb的模块

    是pymysql python2中是MySQL-python sudo pip install pymysql 参考博客https://www.jb51.net/article/140387.htm

  5. (转)webView清除缓存

    NSURLCache * cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses]; [cache setDiskCa ...

  6. Android兼容性测试CTS Verifier-环境搭建、测试执行、结果分析

    CTS Verifier算是CTS的一部分,需要手动进行,主要用于测试那些自动测试系统无法测试的功能,比如相机.传感器等.由于硬件配置或其他原因,不同手机上部分测试项目被隐藏,也就是说CTS Veri ...

  7. HDU 5371 Manacher Hotaru's problem

    求出一个连续子序列,这个子序列由三部分ABC构成,其中AB是回文串,A和C相同,也就是BC也是回文串. 求这样一个最长的子序列. Manacher算法是在所有两个相邻数字之间插入一个特殊的数字,比如- ...

  8. python面试题解析(前端、框架和其他)

    答: HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...

  9. LoadRunner 11破解方法

    名称:HP Loadrunner Software 11.00 版本号:11.00.0.0 安装环境:Win 7 软件安装成功后,会弹出提示告知license的有效期为10天. 破解方法: 1.下载破 ...

  10. 再谈H2的MVStore与MVMap

    对H2的[MVStore]: http://www.cnblogs.com/simoncook/p/5188105.html 这篇文章的补充. 概述 我们通常用的map,比如HashMap Linke ...