Codeforces_714E:Sonya_and_Problem_Wihtout_a_Legend(DP+想法题)
2017-01-14 20:52
471 查看
题目大意是给定n个数字和一种操作,该操作允许你将其中某个数字+1或者-1,求使n个数字变更为严格单调递增所需的最小操作数.
基于离散化+DP的题解在度娘上遍地都是,故不再赘述.
这里是在Codeforces上发现了一种十分新奇的做法,但是lz暂时还无法很好的解释它的原理,然后又怕忘记了,所以在这里贴上代码以防忘记,请静待后续更新0.0
后续1.0: 关于这种做法的原站上的一种说明= =传送门
基于离散化+DP的题解在度娘上遍地都是,故不再赘述.
这里是在Codeforces上发现了一种十分新奇的做法,但是lz暂时还无法很好的解释它的原理,然后又怕忘记了,所以在这里贴上代码以防忘记,请静待后续更新0.0
后续1.0: 关于这种做法的原站上的一种说明= =传送门
#include<iostream> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<vector> #include<queue> using namespace std; #define ll long long priority_queue<ll>a; int main() { ll i,n,k,ans;ans=0; scanf("%I64d%I64d",&n,&k); a.push(k-1); for(i=2;i<=n;i++) { scanf("%I64d",&k);k-=i;a.push(k); if(a.top()>k){ans+=a.top()-k;a.pop();a.push(k);} } cout<<ans; return 0; }
相关文章推荐
- cf/Codeforces Round #371 714E - Sonya and Problem Wihtout a Legend - dp +lis
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)(将一个数组变成严格单增数组的最少步骤)
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)
- 【DP】[CodeForces - 713C]Sonya and Problem Wihtout a Legend
- Codeforces 713C C. Sonya and Problem Wihtout a Legend (经典DP)
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
- Codeforces Round #371 (Div. 2) E. Sonya and Problem Wihtout a Legend(技巧 + 离散化dp)
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
- 【CF713C】Sonya and Problem Wihtout a Legend(离散化,DP)
- hihocoder#1529 : 不上升序列&&Codeforces-713C:Sonya and Problem Wihtout a Legend(思维)
- [堆与斜率] Codeforces 713C - Sonya and Problem Wihtout a Legend
- Codeforces Round #371 (Div. 2) E. Sonya and Problem Wihtout a Legend (DP/LIS变形)
- Codeforces 713 C Sonya and Problem Wihtout a Legend
- 【CodeForces】713 C. Sonya and Problem Wihtout a Legend
- Codeforces-713C-Sonya and Problem Wihtout a Legend
- cf 372 div2 E. Sonya and Problem Wihtout a Legend dp
- 【CF 713C】Sonya and Problem Wihtout a Legend(离散化+dp)<POJ 3666变形>
- Codeforces Round #371 C. Sonya and Problem Wihtout a Legend (DP)
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend