#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,思维)的更多相关文章

  1. Educational Codeforces Round 73 (Rated for Div. 2)E(思维,博弈)

    //这道题博弈的核心就是不能让后手有一段只能放b而长度不够放a的段,并且先手要放最后一次#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h> ...

  2. Educational Codeforces Round 73 (Rated for Div. 2)

    传送门 A. 2048 Game 乱搞即可. Code #include <bits/stdc++.h> #define MP make_pair #define fi first #de ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Educational Codeforces Round 73 (Rated for Div. 2)F(线段树,扫描线)

    这道题里线段树用来区间更新(每次给更大的区间加上当前区间的权重),用log的复杂度加快了更新速度,也用了区间查询(查询当前区间向右直至最右中以当前区间端点向右一段区间的和中最大的那一段的和),也用lo ...

  8. 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\),可加 ...

  9. Educational Codeforces Round 63 (Rated for Div. 2) D dp(最大连续子序列)

    https://codeforces.com/contest/1155/problem/D 题意 一个n个数的数组\(a[i]\),可以选择连续的一段乘x,求最大连续子序列的值 题解 错误思路:贪心, ...

随机推荐

  1. JS中constructor属性

    constructor属性用于对当前对象的构造函数的引用.可以用来判断对象的类型: <script> var newStr = new String("One world One ...

  2. pwnable.kr-random-Writeup

    MarkdownPad Document *:first-child { margin-top: 0 !important; } body>*:last-child { margin-botto ...

  3. 创建Maven project 提示pom.xml 首行错误

    背景 使用eclipse创建Maven SpringBoot 2.2.0 项目时报错,更换springboot 版本也不行,排除框架依赖原因.然后别人的eclipse创建的同样2.2.2 maven项 ...

  4. python+树莓派实现IoT(物联网)数据上传到服务器

    环境:raspbian-stretch(2018-06-27) 树莓派:3代B型 1.树莓派设备,需要在野外也能拥有独立联网能力,那必不可少的需要使用物联网模块. 这里使用的是微雪的SIM868通讯模 ...

  5. 源头质量 PageHelper(分页),导出功能

    今天星期五,本来想直接关电脑走人的,但想想自己弄出来的,写写留个记忆吧.两个功能 导出 和 Mybatis的插件 PageHelper 分页 一,导出功能代码实现:这里是需要jar包的啊 <!- ...

  6. mysql成功的远程连接

    1.在虚拟机上的window7中安装mysql,版本mysql-5.7.27-win32,可以是解压版或者是安装版的, MySQL安装文件分为两种,一种是msi格式的,一种是zip格式的.如果是msi ...

  7. ubuntu中数据迁移的时候出现ImportError错误

    今天在Flask框架中使用数据库迁移的时候出现了如下错误: ImportError: libmysqlclient.so.20: cannot open shared object file: No ...

  8. 批处理执行Testng

    @echo off set LIB=项目的jar路径 set CLASSPATH=%LIB%\jar\commons-beanutils-.jar;%LIB%\jar\testng.jar;%LIB% ...

  9. Scrapy爬取某装修网站部分装修效果图

    爬取图片资源 spider文件 from scrapy.linkextractors import LinkExtractor from scrapy.spiders import CrawlSpid ...

  10. Services: ARP Caching

    Online Help for Cisco IOS Release 12.2(15)JA Services: ARP Caching   ARP caching on the access point ...