Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)
链接:
https://codeforces.com/contest/1221/problem/D
题意:
You have a fence consisting of n vertical boards. The width of each board is 1. The height of the i-th board is ai. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from 2 to n, the condition ai−1≠ai holds.
Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the i-th board by 1, but you have to pay bi rubles for it. The length of each board can be increased any number of times (possibly, zero).
Calculate the minimum number of rubles you have to spend to make the fence great again!
You have to answer q independent queries.
思路:
考虑每个点加0,1, 2,种情况, 往后DP即可.
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 3e5+10;
LL Dp[MAXN][3];
int a[MAXN], b[MAXN];
int n;
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--)
{
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i] >> b[i];
Dp[1][0] = 0;
Dp[1][1] = b[1];
Dp[1][2] = 2*b[1];
for (int i = 2;i <= n;i++)
{
Dp[i][0] = Dp[i][1] = Dp[i][2] = 1e18;
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], min(Dp[n][1], Dp[n][2])) << endl;
}
return 0;
}
Educational Codeforces Round 73 (Rated for Div. 2) D. Make The Fence Great Again(DP)的更多相关文章
- Educational Codeforces Round 73 (Rated for Div. 2)
传送门 A. 2048 Game 乱搞即可. Code #include <bits/stdc++.h> #define MP make_pair #define fi first #de ...
- Educational Codeforces Round 73 (Rated for Div. 2) B. Knights(构造)
链接: https://codeforces.com/contest/1221/problem/B 题意: You are given a chess board with n rows and n ...
- Educational Codeforces Round 73 (Rated for Div. 2) C. Perfect Team
链接: https://codeforces.com/contest/1221/problem/C 题意: You may have already known that a standard ICP ...
- Educational Codeforces Round 73 (Rated for Div. 2) A. 2048 Game
链接: https://codeforces.com/contest/1221/problem/A 题意: You are playing a variation of game 2048. Init ...
- Educational Codeforces Round 73 (Rated for Div. 2)F(线段树,扫描线)
这道题里线段树用来区间更新(每次给更大的区间加上当前区间的权重),用log的复杂度加快了更新速度,也用了区间查询(查询当前区间向右直至最右中以当前区间端点向右一段区间的和中最大的那一段的和),也用lo ...
- Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)
//这道题博弈的核心就是不能让后手有一段只能放b而长度不够放a的段,并且先手要放最后一次#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h> ...
- Educational Codeforces Round 73 (Rated for Div. 2)D(DP,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[300007],b[3 ...
- Educational Codeforces Round 61 (Rated for Div. 2)-C. Painting the Fence 前缀和优化
题意就是给出多个区间,要求去掉两个区间,使得剩下的区间覆盖范围最大. 当然比赛的时候还是没能做出来,不得不佩服大佬的各种姿势. 当时我想的是用线段树维护区间和,然后用单点判0,维护区间间断个数.然后打 ...
- Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem 背包dp
D. Yet Another Subarray Problem You are given an array \(a_1, a_2, \dots , a_n\) and two integers \( ...
随机推荐
- [转帖CCIX]
业界七巨头联手,数据中心通过PCIe实现25Gbps数据通信! 2017-06-07 17:31 CCIX(Cache Coherent Interconnect for Accelerators,针 ...
- AC自动机fail树上dfs序建线段树+动态memset清空
题意:http://acm.hdu.edu.cn/showproblem.php?pid=4117 思路:https://blog.csdn.net/u013306830/article/detail ...
- python — 函数基础知识(二)
目录 1 返回值 2 作用域 3 函数小高级 4 函数中高级 1 返回值 def func(arg): # .... return 9 # 返回值为9 默认:return None val = fun ...
- layui upload 在JS动态加载内容后, 点击按钮无反应
/** * 根据用户选择的不同规格选项 * 返回 不同的输入框选项 */ function ajaxGetSpecInput2(spec_arr) { var goods_id = $('#goods ...
- redhad 7.0更换yum源
1. 卸载红帽yum源 rpm –e $(rpm –qa|grep yum) --nodeps 2.删除所有repo相关文件 rm –rf /etc/yum.conf rm –rf /etc/yum ...
- Educational Codeforces Round 71 (Rated for Div. 2) Solution
A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...
- intellij IDE 破解 简单 License server 法
http://idea.iteblog.com/key.php
- 小程序page中生命周期
onLoad -- 页面被加载出来 onShow -- 页面显示出来后 退出后两小时进来,只会执行这个生命周期 onRady -- (逻辑层传给渲染层后才会执行)监听页面初次渲染完成 onHide ...
- 如何用Visual Studio Code远程调试运行在服务器上的nodejs应用
假设我有一个nodejs应用,运行在AWS - 亚马逊云平台上(Amazone Web Service).我想用本地的Visual Studio Code来远程调试服务器端的nodejs应用. Vis ...
- 2.1 使用JAXP 对 xml文档进行DOM解析
//使用 jaxp 对xml文档进行dom解析 public class Demo2 { //必要步骤 @Test public void test() throws Exception { //1. ...