[題解](DP)CF713C_Sonya and Problem Wihtout a Legend
對於不嚴格單調的我們可以n^2DP,首先每個數一定在原數組中出現過,如果沒出現過不如減小到出現過的那個花費更小,效果相同
所以f[i][j]表示把i改到離散化后j的最小代價,每次維護前一狀態最小值mn再加上這次的值就是答案
圖像沒看懂:https://blog.csdn.net/lycheng1215/article/details/80089004
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=;
const ll inf=1e18+;
int n,a[maxn],b[maxn];
ll f[maxn][maxn],mn[maxn];
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll abs(ll a){return a<?-a:a;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]),a[i]-=i,b[i]=a[i];
sort(b+,b++n);
int bb=unique(b+,b++n)-b-; for(int i=;i<=n;i++){
ll mn=inf;
for(int j=;j<=bb;j++){
mn=min(mn,f[i-][j]);
f[i][j]=abs(b[j]-a[i])+mn;
}
}
ll ans=inf;
for(int i=;i<=bb;i++)
ans=min(ans,f[n][i]);
printf("%lld\n",ans); }
[題解](DP)CF713C_Sonya and Problem Wihtout a Legend的更多相关文章
- 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 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 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 ...
- 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 ...
- Codeforces 713C Sonya and Problem Wihtout a Legend(DP)
题目链接 Sonya and Problem Wihtout a Legend 题意 给定一个长度为n的序列,你可以对每个元素进行$+1$或$-1$的操作,每次操作代价为$1$. 求把原序列变成 ...
- 把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend
//把一个序列转换成严格递增序列的最小花费 CF E - Sonya and Problem Wihtout a Legend //dp[i][j]:把第i个数转成第j小的数,最小花费 //此题与po ...
- 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 ...
- Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend
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 ...
随机推荐
- 【操作系统】使用BCD工具安装Ubuntu操作系统
Ubuntu14.04作为目前最新版本的ubuntu系统,相信很多人都想在自己的电脑上安装一下,然而系统的安装方法各式各样,U盘法.grub引导法等等,本文将介绍在win7系统下用easyBCD软件建 ...
- linux下配置yum源
备份原yum源 /etc/yum.repos.d/centos一base.repo 下载yum源 wagt 源网址/源名称/etc/yum.repos.d/原yum名
- ThinkPHP Widget模块开发流程
初识ThinkPHP的Widget,现把模块开发的流程发布如下,也方便以后自己查阅: 一.新建数据库表self_modules,sql代码如下 CREATE TABLE `self_modules` ...
- Ace(二)Demo示例
Client: #include "ace/Log_Msg.h" #include "ace/OS.h" #include "ace/Service_ ...
- RabbitMQ的安装与客户端的简单实用
本文主要内容是RabbitMQ的安装步骤[Windows系统与linux上的安装]及客户端的简单使用. 1.下载 下载地址:http://www.rabbitmq.com/download.html ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Spring cloud基础模块学习
1.微服务架构构成 单体架构(通过应用集群和数据库集群来提高性能,多余模块存在浪费) 垂直架构(新的功能模块通过新项目来实现,数据库之间存在交叉关联.存在数据冗余,和单体架构一样通过扩展集群结点,成本 ...
- 如何用vs2013开发人员命令提示工具执行一个方法(一个简单的demo)
在任何一个编辑器中编写一个静态的Main方法,必须是静态且名为Main的方法,并将Main方法所在的类文件命名为yang.cs(这个名字随便命名),如图-1. 图-1 打开你的vs2013开发人员命令 ...
- 微信小程序 实现websocket长连接 以及断开连接之后自动重连
app.js let socketMsgQueue = [] let isLoading = false App({ globalData: { userInfo: null, localSocket ...
- 【eclipse插件开发实战】Eclipse插件开发3——OSGi、RCP
Eclipse插件开发实战3--OSGi.RCP 一.OSGi 1. 什么是OSGi框架 OSGi(Open Service Gateway Initiative)框架是运行在JavaVM环境里的服务 ...