Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend
C - Sonya and Problem Wihtout a Legend
思路:感觉没有做过这种套路题完全不会啊。。 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数字。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; LL dp[N][N], a[N], hs[N], tot, n; int main() {
memset(dp, INF, sizeof(dp));
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%lld", &a[i]);
a[i] = a[i] - i;
hs[tot++] = a[i];
}
sort(hs, hs + tot);
tot = unique(hs, hs + tot) - hs; for(int j = ; j < tot; j++) dp[][j] = abs(a[] - hs[j]); for(int i = ; i <= n; i++) {
LL mn = INF;
for(int j = ; j < tot; j++) {
mn = min(mn, dp[i - ][j]);
dp[i][j] = min(dp[i][j], mn + abs(a[i] - hs[j]));
}
}
LL ans = INF;
for(int j = ; j < tot; j++)
ans = min(ans, dp[n][j]);
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩
题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]
C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries
题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- 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 ...
- 【CodeForces】713 C. Sonya and Problem Wihtout a Legend
[题目]C. Sonya and Problem Wihtout a Legend [题意]给定n个数字,每次操作可以对一个数字±1,求最少操作次数使数列递增.n<=10^5. [算法]动态规划 ...
随机推荐
- pdf 下载整理
pdf下载整理: using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 居中div,居中浮动的元素
定位法:position:absolute 如果子级div有定义宽和高的话就可以用这个方法.注意:margin-top,和margin-left的值均为高和宽值的一半 margin:auto法 这个也 ...
- 【转】手摸手,带你用vue撸后台 系列二(登录权限篇)
前言 拖更有点严重,过了半个月才写了第二篇教程.无奈自己是一个业务猿,每天被我司的产品虐的死去活来,之前又病了一下休息了几天,大家见谅. 进入正题,做后台项目区别于做其它的项目,权限验证与安全性是非常 ...
- centos7 ffmpeg安装
#Nux Dextop库依赖于EPEL库,所有要先安装EPEL库yum -y install epel-release #安装Nux Dextop库rpm -Uvh http://li.nux.ro/ ...
- 如何卸载掉eclipse中的插件
First-->Help->About Eclipse Second--> Third-->
- JavaScript 秘密花园——对象的使用和属性操作
JavaScript 中所有变量都是对象,除了两个例外 null 和 undefined. false.toString(); // 'false' [1, 2, 3].toString(); // ...
- JS操作CSS随机改变网页背景
今天有个朋友在weibo上问我可不可以用JS和CSS让页面每次刷新随机产生一张背景图,当然我的回答是可以的.具体可以这样做: 1.用JS定义一个图片数组,里面存放你想要随机展示的图片 1 2 3 4 ...
- IntelliJ Idea key shortcuts
>Default explaination Official IntelliJ Idea 常用快捷键列表 Shortcuts Ctrl+Shift + Enter,语句完成 "!&qu ...
- HDU 1214 圆桌会议 (找规律)
题目链接 Problem Description HDU ACM集训队的队员在暑假集训时经常要讨论自己在做题中遇到的问题.每当面临自己解决不了的问题时,他们就会围坐在一张圆形的桌子旁进行交流,经过大家 ...
- IIS7.5 配置应用程序初始化功能
IIS进程回收后,第一次访问会超级慢,这对于用户是不能接受的,怎么解决这个问题? 我们不能设置IIS不回收进程,因为这样可能会导致IIS内存泄漏.有效的方法时,尽量在业务空闲时间回收进程,回收后立刻预 ...