当前位置:网站首页>Optimal Biking Strategy【DP + 二分】
Optimal Biking Strategy【DP + 二分】
2022-07-17 20:46:00 【Codiplay】
G - Optimal Biking Strategy(DP + 二分)
F[i][j]表示到第i个车站花费不超过j元骑行的最大距离
当前是不超过j元,该状态可以由第id个车站更新而来,花费为cost
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
int a[N], k;
int f[N][10];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, p, s;
cin >> n >> p >> s;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
}
cin >> k;
for (int i = 1; i <= n; i ++ ) {
for (int j = 1; j <= k; j ++ ) {
f[i][j] = f[i - 1][j];
//这个地方要找i这一层的关系,自己体会
//这个地方更新的逻辑是,如果当前状态无法从下面的状态更新过来,他继承的是哪个状态
for (int cost = 1; cost <= j; cost ++ ) {
int mx = cost * s;
//a[i] - a[id] <= mx
// a[id] >= a[i] - mx
int id = lower_bound(a + 1, a + n + 1, a[i] - mx) - a;
if(id == n + 1)continue;
f[i][j] = max(f[i][j], f[id][j - cost] + a[i] - a[id]);
}
}
}
//所以最后找答案直接找f[i][k]就行,你细品,k是j中某个特殊的值
int ans = -1;
for (int i = 1; i <= n; i ++ ) ans = max(ans, f[i][k]);
cout << (p - ans) << '\n';
return 0;
}边栏推荐
猜你喜欢

96. Different binary search trees

Chrome plug-ins for information collection

非凸優化問題經典必看綜述“從對稱性到幾何性”,羅切斯特大學等

Importerror: DLL load failed while importing win32api: the specified program cannot be found.

Take a look at try{}catch{}

NO.6浮点数的表示与运算

FreeRTOS implementation of idle tasks and blocking delay

陶博士月线反转6.0
![洛谷:P3092 [USACO13NOV]No Change G(状压+二分,独特的状态定义,不写会后悔一辈子的题)](/img/b9/8cacd3d4ae1cf014654e0204cb3a62.png)
洛谷:P3092 [USACO13NOV]No Change G(状压+二分,独特的状态定义,不写会后悔一辈子的题)

贝塞尔曲线简单介绍
随机推荐
欧奈尔的RPS曲线的编制方法(陶博士原创)
STL string find substring
009 面试题 SQL语句各部分的执行顺序
2022年中国AI医学影像行业概览报告
微服务调用组件feign实战
Is it safe for Hongye futures to open an account online? Are there any account opening guidelines?
How to avoid global index in pychart? How to cancel the indexing of a folder?
Notes with a face value of 10exp (303)
Some puzzles about data dictionary
揭开服务网格~Istio Service Mesh神秘的面纱
国内外十大erp软件系统排名!
Huawei Technologies:Jonatan Krolikowski | 从设计到部署零接触深度强化学习WLANs
AcWing 136. Adjacent value lookup
Uniapp Gaode map positioning function
【ACWing】2521. 数颜色
类3实践
Redis源码与设计剖析 -- 2.链表
分析并HOOK SSHD来劫持密码
"Technology podcast month" day 10: meta podcast: talk about Podcasting
Ranking and evaluation of the second "green tree Cup" Mathematics Competition
