首页 > 其他 > 详细

Sonya and Problem Wihtout a Legend CodeForces - 714E (dp)

时间:2019-04-24 01:08:52      阅读:152      评论:0      收藏:0      [点我收藏+]

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

原文:https://www.cnblogs.com/uid001/p/10760019.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!