Codeforces Round #210 (Div. 1) B. Levko and Array(dp 思维)
来源:互联网 发布:软件危机的例子 编辑:程序博客网 时间:2024/05/17 11:33
Levko has an array that consists of integers: a1, a2, ... , an. But he doesn’t like this array at all.
Levko thinks that the beauty of the array a directly depends on value c(a), which can be calculated by the formula:
It’s time to change the world and Levko is going to change his array for the better. To be exact, Levko wants to change the values of at most k array elements (it is allowed to replace the values by any integers). Of course, the changes should make the array as beautiful as possible.
Help Levko and calculate what minimum number c(a) he can reach.
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 2000). The second line contains space-separated integers a1, a2, ... , an( - 109 ≤ ai ≤ 109).
A single number — the minimum value of c(a) Levko can get.
5 24 7 4 7 4
0
3 1-100 0 100
100
6 31 2 3 7 8 9
1
#include<cmath>#include<algorithm>#include<cstring>#include<string>#include<set>#include<map>#include<time.h>#include<cstdio>#include<vector>#include<stack>#include<queue>#include<iostream>using namespace std;#define LONG long longconst LONG INF=0x3f3f3f3f;const LONG MOD=1e9+7;const double PI=acos(-1.0);#define clr0(x) memset(x,0,sizeof x)#define clrI(x) memset(x,-1,sizeof(x))#define clr1(x) memset(x,INF,sizeof x)#define clr2(x) memset(x,-INF,sizeof x)#define EPS 1e-10LONG n ,k;LONG a[3000];LONG dp[3000];bool check(LONG x){ dp[1] = 0; for(int i = 2; i <= n ;++ i) { dp[ i] = i - 1; for(int j = i- 1 ;j >= 1; --j) if( abs(a[i] - a[j]) <= x * (i - j)) dp[i] = min (dp[i] , dp[j] + i - j - 1); if(dp[i] + n - i <= k)return 1; } return 0;}int main(){ cin>>n>>k; if( n <=1) { cout<<0<<endl; return 0; } for(int i = 1; i<=n ;++ i)cin>>a[i] ; LONG l = 0 , r = 3e9; LONG mid ; while(l < r) { mid = (l + r )/2 ; if(check(mid)) r = mid ; else l = mid + 1; } cout<<l<<endl;}
- Codeforces Round #210 (Div. 1) B. Levko and Array(dp 思维)
- Codeforces Round #210 (Div. 1)——Levko and Array
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- CodeForces 360 B.Levko and Array(二分+dp)
- CF-Codeforces Round #210 (Div. 1)-A-Levko and Array Recovery
- Codeforces Round #210 (Div. 1) problem C Levko and Strings
- Codeforces Round #210 (Div. 1) C. Levko and Strings
- codeforces 360B Levko and Array (dp神题)
- CodeForces 360A - Levko and Array Recovery (思维)
- Codeforces 360B Levko and Array
- Codeforces #360B: Levko and Array 题解
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array(简单莫队)
- 记某次codeforces考试 B. Levko and Array
- CodeForces 361D Levko and Array(二分+dp)
- Codeforces 361D Levko and Array【二分+dp】好题!
- 从JobSchedulerService开始探究学习安卓framework层
- OC学习记录1:类方法与实例方法
- 庖丁解牛<c++primer>系列二:const关键字
- 20170305-java
- Mac在Finder直接打开iterm2并且定位到当前目录 ---------类似于git bash here
- Codeforces Round #210 (Div. 1) B. Levko and Array(dp 思维)
- 有关程序员的十个预言
- caffe学习笔记23-GoogLeNet论文笔记
- java保留2位小数的五种方法总结
- JavaScript中的闭包
- Android java与html js交互 html视频播放没有画面 画面卡顿
- 【HDU-oj】-2157-How many ways??(矩阵)
- 【django3】Django学习笔记3:Model,Template,View 基本概念
- [BZOJ2741][[FOTILE模拟赛]][可持久化Trie+分块]