专栏文章
题解:CF1221D Make The Fence Great Again
CF1221D题解参与者 2已保存评论 1
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @minlqd7h
- 此快照首次捕获于
- 2025/12/02 04:28 3 个月前
- 此快照最后确认于
- 2025/12/02 04:28 3 个月前
DP
定义
分别表示 增加 的长度且满足条件的最小花费。
因为每个 每次上升的长度不超过 ,这点容易证明,这里不详细说了。
转移
答案
代码
CPP#include<bits/stdc++.h>
#define int long long
#pragma GCC optimize(3)
using namespace std;
const int maxn = 300010;
const int inf = 1e18;
const int hs = 131;// 或 1331
//unsigned long long
//cout << fixed << setprecision(3)
//cout << setw(5) <<
//continue
int a[maxn], b[maxn], dp[maxn][3];
signed main(){
freopen("fence.in", "r", stdin);
freopen("fence.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i] >> b[i];
for(int i = 1;i <= n;i++){
dp[i][0] = dp[i][1] = dp[i][2] = inf;
for(int j = 0;j < 3;j++){
for(int k = 0;k < 3;k++){
if(a[i - 1] + k != a[i] + j) dp[i][j] = min(dp[i][j], dp[i - 1][k] + b[i] * j);
}
}
}
cout << min({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}
return 0;
}
感谢阅读!
相关推荐
评论
共 1 条评论,欢迎与作者交流。
正在加载评论...