This commit is contained in:
Zengtudor 2024-10-13 13:36:20 +08:00
parent 0de7fbaabb
commit 3039ac5e93
3 changed files with 50 additions and 7 deletions

View File

@ -36,4 +36,12 @@ void bfs(){
set_color(i, 1); set_color(i, 1);
vis[i]=true; // 注意初始化错误 vis[i]=true; // 注意初始化错误
while(!q.empty()){ while(!q.empty()){
```
### [P3957](https://www.luogu.com.cn/problem/P3957)
#### 初始状态依赖已走过的部分时注意起始点状态
```cpp
for(ll coin{0};coin<=(points[n].posit-d);++coin){
for(ll i{0};i<max_n;i++)dp[i]=ll_min;
dp[0]=0; // 注意第0个点是能到达的reachable
``` ```

View File

@ -4,7 +4,6 @@
#include <algorithm> #include <algorithm>
using ll = long long; using ll = long long;
using std::endl;
static auto &is = std::cin; static auto &is = std::cin;
static auto &os = std::cout; static auto &os = std::cout;

View File

@ -1,17 +1,53 @@
#include <cstring>
#include <iostream> #include <iostream>
#include <bitset> #include <algorithm>
#include <limits>
#include <type_traits>
using ll = unsigned long long; using ll = long long;
auto &is = std::cin; auto &is = std::cin;
auto &os = std::cout; auto &os = std::cout;
const ll /*max_n = 5e5+5*/max_n = 500+5, max_d = 2e3+5, max_x = 1e9+5, max_k = 1e9+5; const ll max_n = 5e5+5, ll_min{std::numeric_limits<decltype(ll_min)>::min()};
ll n, d, k;
struct Point{
ll posit,score;
}points[max_n];
ll dp[max_n];
ll n,d,k; void flush_exit(){
std::bitset<max_n> dp[max_d][max_n][max_n]; os<<std::flush;
_Exit(0);
}
int main(){ int main(){
is>>n>>d>>k; is>>n>>d>>k;
for(ll i{1};i<=n;++i){
is>>points[i].posit>>points[i].score;
}
for(ll coin{0};coin<=(points[n].posit-d);++coin){
for(ll i{0};i<max_n;i++)dp[i]=ll_min;
dp[0]=0; // 注意第0个点是能到达的reachable
const ll max_step {coin+d}, min_step {std::max((ll)1,d-coin)};
for(ll i{1};i<=n;++i){
for(ll from{i-1};from>=0;from--){
ll dis{points[i].posit-points[from].posit};
if(min_step<=dis){
if(dis<=max_step){
if(dp[from]==ll_min)continue;
dp[i] = std::max(dp[i],dp[from]+points[i].score);
if(dp[i]>=k){
os<<coin<<'\n';
flush_exit();
}
}else{
break;
}
}
}
}
}
os<<-1<<'\n';
} }