[題解](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 ...
随机推荐
- iOS 判定string是不是中文字符
+(BOOL)IsChinese:(NSString *)str { ; i< [str length];i++) { int a = [str characterAtIndex:i]; if( ...
- /dev/sda2 is mounted; will not make a filesystem here!
一定要记住,不可以在分区挂载之后再进行格式化!!在错误提示当中可以看出你的分区已经挂载了.先将这个分区卸载了再重新格式化:umount /dev/sda2mkfs.ext2 /dev/sda2这样就没 ...
- ansible-playbook unarchive模块
先 进行 pause模块的 记录: pause 在playbook执行的过程中暂停一定时间或者提示用户进行某些操作 常用参数: minutes:暂停多少分钟 seconds:暂停多少秒 prompt ...
- nginx + ffmpeg
第一种方案:ffmpeg+nginx 新的ffmpeg已经支持HLS.(本人也参与了代码供献,给自己做个广告:)) 点播: 生成hls分片: ffmpeg -i <媒体文件> -c:v l ...
- Service的两种启动方式
今天又写Service,提示覆写onBind(),想起Android好像是有个叫做Binder的IPC机制. Service里面有一个onBind(),一个onStartCommand(),两者都能启 ...
- Android Dalvik虚拟机
虽然Android平台使用Java来开发应用程序,但Android程序却不是运行在标准Java虚拟机上的. 可能是出于效率和版权的考虑,Google为Android专门设计了一套虚拟机Dalvik V ...
- P2383 狗哥玩木棒
题目背景 狗哥又趁着语文课干些无聊的事了... 题目描述 现给出一些木棒长度,那么狗哥能否用给出的木棒(木棒全用完)组成一个正方形呢? 输入输出格式 输入格式: 输入文件中的第一行是一个整数n表示测试 ...
- AndroidStudio设置“自动导入包”
setting –-> Editor –-> General –-> Auto Inport 勾选这两项 单击 Apply –-> ok
- P-Function
题意: 对于集合 $S = {1, 2, ...., n}$ , 定义函数 $F(x) = y, x, y$ 属于 $S$,对于任何 $x$ 属于 $S$, 有 $F(F...F(x)) = x$, ...
- tetrahedron
题意: 求解一个四面体的内切球. 解法: 首先假设内切球球心为$(x0,x1,x2)$,可以用$r = \frac{3V}{S_1+S_2+S_3+S_4}$得出半径, 这样对于四个平面列出三个方程, ...