【题目链接】 http://codeforces.com/problemset/problem/713/C

【题目大意】

  给出一个数列,请你经过调整使得其成为严格单调递增的数列,调整就是给某些位置加上或者减去某个数,调整的代价是加上或者减去的数的绝对值之和,请你输出最小代价。

【题解】

  先考虑这样一个问题,如果是非严格单调递增该如何做,我们会发现每次调整,都是调整某个数字为原先数列中存在的数字,最后才是最优的,所以,我们设DP[i][j]表示前i个数字,最后一个数为原先数列排序后第j大的数字的最小代价,那么做一遍n2的DP就能够获得答案,现在题目中要求的是严格单调递增,那么就用到一种经典的处理方法,a[i]=a[i]-i,这样子就转化为非严格单调的问题了。

【代码】

#include <cstdio>
#include <algorithm>
using namespace std;
const int N=3010;
int n,a[N],b[N];
long long dp[N][N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",a+i);
a[i]-=i; b[i]=a[i];
}sort(b+1,b+n+1);
for(int i=1;i<=n;i++){
long long mn=dp[i-1][1];
for(int j=1;j<=n;j++){
mn=min(mn,dp[i-1][j]);
dp[i][j]=abs(a[i]-b[j])+mn;
}
}long long ans=dp[n][1];
for(int i=1;i<=n;i++)ans=min(ans,dp[n][i]);
printf("%I64d\n",ans);
return 0;
}

  

Codeforces 713C 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. 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 ...

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

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

  4. Codeforces 713C Sonya and Problem Wihtout a Legend

    题意:给一个序列,可以进行若干次操作,每次操作选择一个数让它+1或-1,问最少要几次操作使得序列变为严格单调递增序列. 题解:首先考虑非严格递增序列,则每个数字最终变成的数字一定是该数组中的某个数.那 ...

  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 714E Sonya and Problem Wihtout a Legend(单调数列和DP的小研究)

    题意:给你n个数字,每个数字可以加减任何数字,付出变化差值的代价,求最后整个序列是严格单调递增的最小的代价. 首先我们要将这个题目进行转化,因为严格单调下是无法用下面这个dp的方法的,因此我们转化成非 ...

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

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

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

随机推荐

  1. leetcode Letter Combinations of a Phone Number python

    class Solution(object): def letterCombinations(self, digits): """ :type digits: str : ...

  2. mysql5.1 有什么新特性

    本章介绍 新特性和已过时的特性 新特性: 1.分隔 这个特性允许把一个表里的部分数据放入文件系统中,它会根据表的创建规则来存储,一个表的不同部分被存储在不同的物理地址下.不过这个特性对于用户是不可见的 ...

  3. JavaScript 你好!

    JavaScript简介 开发时间:1995年 开发目的:一开始的目的是处理以前由服务器端语言(如perl)负责的一些输入验证操作. 现状:现在的用途不再局限于简单的数据验证,而是具备了与浏览器窗口及 ...

  4. 使用mysql_query()方法操纵数据库以及综合实例

    1.利用insert 语句添加记录 <? require('conn.php'); mysql_query( "insert into lyb ( title, content, au ...

  5. the C programming language 阅读笔记2

    1. 指针 1.1 自增符的使用 ++*p;//p指向的内容加一 (*p)++; //p指向的内容加一 *p++;//p本身自增 *++p; //p本身自增 因为诸如*和++这样的一元运算符在表达式求 ...

  6. WinSetupFromUSB – Install Windows XP from USB Flash Drive

    http://myeeeguides.wordpress.com/2008/11/15/winsetupfromusb-install-windows-xp-from-usb-flash-drive/ ...

  7. iOS 视图跳转

    //跳转 - ( void)present:( id )sender { NSLog ( @"the button,is clicked …" ); // 创建准备跳转的 UIVi ...

  8. 『HTML5梦幻之旅』-缤纷多姿的烟花效果

    天花无数月中开,五采祥云绕绛台.堕地忽惊星彩散,飞空旋作雨声来.怒撞玉斗翻晴雪,勇踏金轮起疾雷.更漏已深人渐散,闹竿挑得彩灯回. ——明·瞿佑·<烟火戏> 记得每年过春节的那段时间,除了欣 ...

  9. 奔五的人,准备学习iOS开发

    这些年一直在java/web/android方面折腾,去年最终换成了apple的设备,本想就開始折腾iOS,却始终没能进入状态. 从今天開始,本人宣布:正式进入iOS/xcode 5的编程学习中,也希 ...

  10. zoj 3665 Yukari's Birthday(枚举+二分)

    Yukari's Birthday Time Limit: 2 Seconds       Memory Limit: 32768 KB Today is Yukari's n-th birthday ...