Codeforces Round #371 (Div. 2) E
来源:互联网 发布:pca算法matlab代码 编辑:程序博客网 时间:2024/05/20 23:58
E
题目地址:http://codeforces.com/contest/714/problem/E
思路:基本就是原题的另一题地址:http://codeforces.com/contest/13/problem/C,多加一个 -i 的处理。
AC代码:
#include<bits/stdc++.h>using namespace std;const int maxn=3000+15;int a[maxn],b[maxn];long long dp[maxn][maxn];int n;int main(){ while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { int temp; scanf("%d",&temp); a[i]=b[i]=temp-i; } sort(b+1,b+1+n); for(int i=1;i<=n;i++) { dp[i][1]=dp[i-1][1]+(long long)abs(a[i]-b[1]); for(int j=2;j<=n;j++) dp[i][j]=min(dp[i][j-1],dp[i-1][j]+(long long)abs(a[i]-b[j])); } printf("%I64d\n",dp[n][n]); }}
0 0
- Codeforces Round #371 (Div. 2) E
- Codeforces Round #371 (Div. 2) E dp
- 解题报告:Codeforces Round #371 (Div. 2) A~E
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #102 (Div. 2) //缺E
- Codeforces Round #104 (Div. 2) //缺E
- Codeforces Round #105 (Div. 2) //缺E
- Codeforces Round #103 (Div. 2) //缺E
- Codeforces Round #106 (Div. 2) //缺E
- Codeforces Round #223 (Div. 2) E
- Codeforces Round #229 (Div. 2) E
- Codeforces Round #139 (Div. 2) E. Unsolvable
- Codeforces Round #142 (Div. 2) E. Triangles
- Codeforces Round #256 (Div. 2) E. Divisors
- [2016ICPC 大连网络预选赛] HDU5876 图论
- EL表达式取值
- linux运维-log日志管理
- 双系统Ubuntu无法进入Windows磁盘的解决方法
- php的Master Value不起作用
- Codeforces Round #371 (Div. 2) E
- nfs权限设置
- 非对称加密到底有哪些用途(RAS实现)
- sqlserver中All、Any和Some用法与区别
- Leetcode_20
- Spring Boot系列(十八) 缓存
- Java.Web:Servlet/Filter中的 <url-pattern>
- 前缀树,Trie树
- 央视直播协议分析