DP Codeforces Round #303 (Div. 2) C. Woodcutters
/*
题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒
问最多能砍到多少棵树
DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树
分情况讨论,若符合就取最大值更新,线性dp,自己做出来了:)
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std; typedef long long LL; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
LL x[MAXN], h[MAXN];
LL dp[MAXN][]; //0-l 1-no 2-r int main(void) //Codeforces Round #303 (Div. 2) C. Woodcutters
{
//freopen ("C.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
for (int i=; i<=n; ++i)
{
scanf ("%I64d%I64d", &x[i], &h[i]);
}
memset (dp, , sizeof (dp));
dp[][] = dp[][] = ;
if (x[] + h[] < x[]) dp[][] = ;
for (int i=; i<=n; ++i)
{
LL tmp;
tmp = max (dp[i-][], dp[i-][]);
tmp = max (tmp, dp[i-][]);
dp[i][] = tmp;
if (x[i] - h[i] > x[i-])
{
dp[i][] = max (dp[i-][], dp[i-][]) + ;
}
if (x[i] - x[i-] > h[i-] + h[i])
{
dp[i][] = max (dp[i][], dp[i-][] + );
}
if (i < n && x[i] + h[i] < x[i+])
{
dp[i][] = tmp + ;
}
if (i == n) dp[i][] = tmp + ;
} LL ans;
ans = max (dp[n][], dp[n][]);
ans = max (ans, dp[n][]);
printf ("%I64d\n", ans);
} return ;
}
DP Codeforces Round #303 (Div. 2) C. Woodcutters的更多相关文章
- Codeforces Round #303 (Div. 2) C. Woodcutters 贪心
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- 水题 Codeforces Round #303 (Div. 2) D. Queue
题目传送门 /* 比C还水... */ #include <cstdio> #include <algorithm> #include <cstring> #inc ...
- 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
随机推荐
- Sharepoint2013 列表的NewForm 页面加入一个 保存新建 button
昨天一同事问我怎样在sharepoint2013的NewForm.aspx页面上加入一个 save and new的button.实现save 和new的功能.save的功能和默认的save按钮效果一 ...
- XJTUOJ wmq的A×B Problem FFT/NTT
wmq的A×B Problem 发布时间: 2017年4月9日 17:06 最后更新: 2017年4月9日 17:07 时间限制: 3000ms 内存限制: 512M 描述 这是一个非常简 ...
- JS中prototype,js原型扩展
作者:轩脉刃(yjf512)出处:(http://www.cnblogs.com/yjf512/)版权声明:本文的版权归作者与博客园共有.欢迎转载阅读,转载时须注明本文的详细链接. 原文 http:/ ...
- About "self"
Class method can't refer derectly to instance variables. Within the body of a class method, self re ...
- HashTable HashMap区分
主要是安全.速度: 1.HashMap可以接受null的键. 2.HashMap是非synchronized,而Hashtable是synchronized,这意味着Hashtable是线程安全的,多 ...
- GPS常见故障
当出现故障时,依据可能原因进行排查. 下表列举典型故障及调试方法 现象 root cause 检查 实验 GPS无法开启/无法搜星 软件配置错误 SW 相关配置(如GPIO等) 录制mobile ...
- VMWare Workstation 配置docker多macvlan网络方法
VMWare Workstation 配置docker多macvlan网络方法 答案就是.....换VirtualBox 噗... VMWare Workstation host-only网络,三台虚 ...
- YTU 2456: 评委打分
2456: 评委打分 时间限制: 1 Sec 内存限制: 128 MB 提交: 283 解决: 52 题目描述 一个歌唱比赛,比赛每次会从观众中随即抽取几名观众给分(观众至少有5个,分数为0~1 ...
- hdu 2594 Simpsons’ Hidden Talents(两个串的next数组)
题意:两个字符串s.t,求s和t的最长的相同的前缀和后缀 思路:先求s的next数组,再求t的next数组(即代码中ex数组,此时不是自己与自己匹配,而是与s匹配),最后看ex[len2]即可(len ...
- PHP自动发送邮件
目录 1. PHPMailer 2. 集成ThinkPHP 2.1 类库重命名 2.2 配置SMTP服务器 2.3 使用 1. PHPMailer 在自己项目引入核心类库文件 require_once ...