Codeforces 1076F Summer Practice Report dp
dp[ i ][ 0 ]表示放完前 i 页, 第 i 页最后一段是 0, 0个数的最小值。
dp[ i ][ 1 ]表示放完前 i 页, 第 i 页最后一段是 1, 1个数的最小值。
这个转移细节有点多。。。
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 3e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T> bool chkmax(T& a, T b) {
return a < b ? a = b, true : false;
}
template<class T> bool chkmin(T& a, T b) {
return a > b ? a = b, true : false;
} int n, x[N], y[N];
LL k;
int dp[N][]; int calc(int prea, int a, int b, int op) {
if(!op) {
if(k - prea + b * k < a) return inf;
if(a * k < b) return inf;
if(k - prea + (b - ) * k < a - ) return a - (k - prea + (b - ) * k);
return ;
} else {
if(k - prea + (b - ) * k < a) return inf;
if((a + ) * k < b) return inf;
if(a * k < b - ) return b - a * k;
return ;
}
} int main() {
scanf("%d%lld", &n, &k);
for(int i = ; i <= n; i++) scanf("%d", &x[i]);
for(int i = ; i <= n; i++) scanf("%d", &y[i]);
memset(dp, inf, sizeof(dp));
dp[][] = dp[][] = ;
for(int i = ; i < n; i++) {
if(dp[i][] <= k) {
chkmin(dp[i + ][], calc(dp[i][], x[i + ], y[i + ], ));
chkmin(dp[i + ][], calc(dp[i][], x[i + ], y[i + ], ));
}
if(dp[i][] <= k) {
chkmin(dp[i + ][], calc(dp[i][], y[i + ], x[i + ], ));
chkmin(dp[i + ][], calc(dp[i][], y[i + ], x[i + ], ));
}
}
if(dp[n][] > k && dp[n][] > k) {
puts("NO");
} else puts("YES");
return ;
} /*
*/
Codeforces 1076F Summer Practice Report dp的更多相关文章
- Codeforces1076F. Summer Practice Report(贪心+动态规划)
题目链接:传送门 题目: F. Summer Practice Report time limit per test seconds memory limit per test megabytes i ...
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...
- codeforces 721C (拓排 + DP)
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知 ...
- codeforces 711C Coloring Trees(DP)
题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后bea ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces 543D. Road Improvement (树dp + 乘法逆元)
题目链接:http://codeforces.com/contest/543/problem/D 给你一棵树,初始所有的边都是坏的,要你修复若干边.指定一个root,所有的点到root最多只有一个坏边 ...
- Codeforces 467C. George and Job (dp)
题目链接:http://codeforces.com/contest/467/problem/C 求k个不重叠长m的连续子序列的最大和. dp[i][j]表示第i个数的位置个序列的最大和. 前缀和一下 ...
- Codeforces 711 C. Coloring Trees (dp)
题目链接:http://codeforces.com/problemset/problem/711/C 给你n棵树,m种颜色,k是指定最后的完美值.接下来一行n个数 表示1~n树原本的颜色,0的话就是 ...
- Codeforces 706 C. Hard problem (dp)
题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满 ...
随机推荐
- Linux 安装Python和Django
1.下载python源码包 网址: https://www.python.org/ 在Downloads中打开Source code 由于 Django1.11.15不兼容3.7版本的python 所 ...
- linux进程内存布局
一个程序本质上都是由 BSS 段.data段.text段三个组成的.这样的概念在当前的计算机程序设计中是很重要的一个基本概念,而且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统运行时的内存大小分 ...
- 如何取出DataTable中某几个字段(列名)组合新表
在偶不知道第二种方法之前.偶费了好大劲才把这个问题解决.下面把这两个方法都帖出来,请大家批评指正.或有更好的办法也帖出来,一起交流 第一种方法: string sql = &qu ...
- linux命令排序
sort -k1 -n 第一列按数字正排序 sort -K1 -rn 第一列按数字倒排序
- 2018谷歌I/O开发者大会8大看点汇总 新品有哪些
2018谷歌I/O开发者大会8大看点汇总 新品有哪些美国科技媒体The Verge近日撰文,列举了在即将召开的2018年谷歌I/O开发者大会上的8大看点,包括Android P.人工智能等等. 以下为 ...
- swift 实践- 08 -- UISegmentedControl
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- 在XIB 或者 SB 上面 实现 半透明的背景上添加UILabel是文字不透明
设透明背景的时候直接设置RGB值 然后设置Opacity即可
- Oracle 系统调优
一:前言 一:调整初始化参数 1: Oracle 初始化参数分类 2:主要系统调优参数介绍 二:系统全局区 sga 优化 1:调整内存分配 2:调整日志缓冲区 1:查询当前oracle 实例的日志缓冲 ...
- D3.js 使用缩放zoom时节点无法拖动,只能整体移动的问题
.on("dragstart", function() { d3.event.sourceEvent.stopPropagation(); }) https://stackover ...
- 通过$broadcast或$emit在子级和父级controller之间进行值传递
通过$broadcast或$emit在controller之间进行值传递,不过这些controller必须是子级或者父级关系, $emit只能向父级parent controller传递事件event ...