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[300007];
long long dp[300007][5];
long long ans;
int main(){
ios::sync_with_stdio(false);//多组数据输入cin,cout容易超时
cin.tie(NULL);
cout.tie(NULL);
int q;
cin>>q;
while(q--){
int n;
ans=2e18;
cin>>n;
dp[1][0]=0;//第二维表示第一维增加的高度,0即不增加,花费也是0
dp[1][1]=b[1];//增加1高度花费为b[1]
dp[1][2]=2e18;//第一个点最多只需要增加1高度就可以与a[2]不同,所以花费初始化为最大值
for(int i=2;i<=n;++i){//初始化
dp[i][0]=2e18;
dp[i][1]=2e18;
dp[i][2]=2e18;
}
for(int i=1;i<=n;++i)
cin>>a[i]>>b[i];
for(int i=2;i<=n;++i){
for(int j=0;j<3;++j){
for(int k=0;k<3;++k){
if(k+a[i]!=a[i-1]+j){//如果当前a[i]增加k以后的高度和上一位置a[i-1]增加j以后的高度不同,则满足题意
dp[i][k]=min(dp[i-1][j]+b[i]*k,dp[i][k]);//更新位置i增加高度k所需要的最小花费
}
}
}
}
for(int i=0;i<3;++i){
ans=min(dp[n][i],ans);
}
cout<<ans<<"\n";
}
return 0;
}
Educational Codeforces Round 73 (Rated for Div. 2)D(DP,思维)的更多相关文章
- 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)
传送门 A. 2048 Game 乱搞即可. Code #include <bits/stdc++.h> #define MP make_pair #define fi first #de ...
- 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 boar ...
- 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 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...
- Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)
https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...
随机推荐
- label 阻止冒泡 防止点击label 触发2次事件
// 必须要把 jnput的外面的label加上事件阻止冒泡,否则点击label的时候,会冒泡到input上 再次触发input的点击事件 $('.xt_order_cleft_modb_rl_dx' ...
- ARM架构Linux环境安装python2.7.9
1.下载python # wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz 2.解压.编译安装 # tar -zxvf Pyt ...
- android基础控件的使用
控件在屏幕上位置的确定 通常情况下控件在屏幕上确定至少要连接两条线(一条水平,一条垂直) 如下图连接了四条线 辅助线 辅助线的调出: 水平辅助线:进入activity.xml的设计模式之后如下图 为了 ...
- PAT 1010 Radix (二分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- 你了解真正的 restful API 吗?
本文原创地址,博客:https://jsbintask.cn/2019/03/20/api/restful-api-best-practices/(食用效果最佳),转载请注明出处! 前言 在以前,一个 ...
- 树莓派下编译并使用miracl密码库
参考:Linux下编译并使用miracl密码库 MIRACL用户手册:https://wenku.baidu.com/view/d542f2ed0975f46527d3e1dc.html 具体过程. ...
- ASP.NET Core搭建多层网站架构【9.1-使用Autofac代替原生的依赖注入】
2020/01/30, ASP.NET Core 3.1, VS2019, Autofac.Extensions.DependencyInjection 5.0.1 摘要:基于ASP.NET Core ...
- python 环境迁移之requirements.txt (window环境)
一.背景 1.有时候你本地用python编写代码,然后本地也安装了很多的库,那么你要迁移到服务器上,那么该怎么快速弄环境库呢? #第二,三步就可以解决. 2.有时候你本地用pyth ...
- Linux 常用命令——查看系统
有的时候别人给你一个登录方式,但是不知道是啥系统,看图就知道了 1.uname -a 查看电脑以及操作系统 2.cat /proc/version 正在运行的内核版本 3.cat /etc/is ...
- 创建Ajax兼容
var request = new XMLHttpRequest(); IE7以下: var request = new ActiveXObject("Microsoft.XMLHTTP&q ...