Codeforces 1221D. Make The Fence Great Again
容易想到 $dp$,但是如果直接设 $f[i][j]$ 表示修正完前 $i$ 个位置,第 $i$ 个位置增加了 $j$ 高度显然是不行的
考虑有性质,发现每个位置只会被左右两个位置影响而改变,即如果一边等于它那么才要考虑增加它的位置,并且如果此时另一边恰好比它原本高度大 $1$,这个位置才要再考虑增加高度
所以容易发现,每个位置最多增加 $2$ 的高度,然后就可以直接 $dp$ 了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=6e5+;
const ll INF=1e18+;
int Q,n,a[N],b[N];
ll f[N][];
int main()
{
Q=read();
memset(f,0x3f,sizeof(f));
while(Q--)
{
for(int i=;i<=n;i++) f[i][]=f[i][]=f[i][]=INF;
n=read(); for(int i=;i<=n;i++) a[i]=read(),b[i]=read();
f[][]=; f[][]=f[][]=INF;
for(int i=;i<=n;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
if(a[i-]+k!=a[i]+j)
f[i][j]=min(f[i][j],f[i-][k]+1ll*b[i]*j);
ll ans=INF; for(int i=;i<;i++) ans=min(ans,f[n][i]);
printf("%lld\n",ans);
}
return ;
}
Codeforces 1221D. Make The Fence Great Again的更多相关文章
- codeforces 349B Color the Fence 贪心,思维
1.codeforces 349B Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...
- Codeforces 484E Sign on Fence(是持久的段树+二分法)
题目链接:Codeforces 484E Sign on Fence 题目大意:给定给一个序列,每一个位置有一个值,表示高度,如今有若干查询,每次查询l,r,w,表示在区间l,r中, 连续最长长度大于 ...
- codeforces B. Color the Fence 解题报告
题目链接:http://codeforces.com/problemset/problem/349/B 题目意思:给定v升的颜料和9个需要花费ad 升的颜料,花费ad 升的颜料意味着得到第d个数字,现 ...
- 【贪心】Codeforces 349B.Color the Fence题解
题目链接:http://codeforces.com/problemset/problem/349/B 题目大意 小明要从9个数字(1,2,--,9)去除一些数字拼接成一个数字,是的这个数字最大. 但 ...
- Codeforces 1132C - Painting the Fence - [前缀和优化]
题目链接:https://codeforces.com/contest/1132/problem/C 题意: 栅栏有 $n$ 个节,有 $q$ 个人可以雇佣来涂栅栏,第 $i$ 个人可以涂第 $l_i ...
- Codeforces 349B - Color the Fence
349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...
- Codeforces 448 C. Painting Fence
递归.分治. . . C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input ...
- Codeforces D. Color the Fence(贪心)
题目描述: D. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces 448C:Painting Fence 刷栅栏 超级好玩的一道题目
C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...
随机推荐
- JETSON TK1 ~ 安装Cuda和OpenCV3
一:安装Cuda6.5 1:下载安装包 Cuda6.5 2.在TK1上安装软件包: cd ~/Downloads sudo dpkg -i cuda-repo-l4t-r21.3-6-5-prod_6 ...
- 使用 VS2015 编译并调试 ffmpeg
导读 ffmpeg 是音频处理方面非常强大非常有名的开源项目了,然而如 雷神 所说,“FFMPEG 难度比较大,却没有一个循序渐进,由简单到复杂的教程.现在网上的有关FFMPEG的教程多半难度比较大, ...
- java获取来访者mac信息
根据IP获取对应的Mac地址,支持win10+Linux package com.simonjia.util.other; /** * @Author: SimonHu * @Date: 2019/6 ...
- Ubuntu——关于以root权限操作和启用root账户的讨论
概括性的说,在Ubuntu下面,推荐用户加入到sudo之后,使用命令: sudo -i 来以管理员权限进行操作. 而不推荐用户直接登录root用户. 具体内参考:https://help.ubuntu ...
- 云服务器 ECS 是什么?
云服务器 Elastic Compute Service(ECS)是阿里云提供的一种基础云计算服务.使用云服务器 ECS 就像使用水.电.煤气等资源一样便捷.高效.您无需提前采购硬件设备,而是根据业务 ...
- android 9.0以上charles https抓包
以前安装证书的方式无效了,必须将下载的证书复制到/system/etc/security/cacerts/目录, 步骤: 1.现在手机上安装好 chls.pro/ssl下载得到一个 charles-p ...
- GCC 9.2 2019年8月12日 出炉啦
GNU 2019-08-12 发布了 GCC 9.2https://gcc.gnu.org/onlinedocs/9.2.0/ 有详细的说明 MinGW 上可用的 GCC 9.2 版本下载地址 [ m ...
- 在Excel工作表单元格中引用当前工作表名称
在Excel工作表单元格中引用当前工作表名称 有多份Excel表格表头标题都为"××学校第1次拉练考试××班成绩表",由于工作表结构都是一样的,所以我每次都是复制工作表然后编辑修改 ...
- "UICollectionView实现带头视图和组的头视图同时存在"实现
实现效果如下: 以前做这效果的界面,总是实现的是section的头视图,因为我一直觉得collectionView是不像UITableView那样有tableHeaderView的,所以每次实现只能是 ...
- 实验一 part2
#include <stdio.h> int main () { int x; printf("输入一个整数:\n"); scanf("%d",&a ...