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. 经过操作后是否能满 ...
随机推荐
- maven本地上传jar包
maven本地上传jar包 在命令行中输入下面指令(是一行): mvn install:install-file -Dfile=D:\mvn\spring-context-support-3.1.0. ...
- opensips redis配置记录
说明:本配置目的:增加opensips对 Redis 的支持. 一.步骤: 1.Redis Server 安装. 2.Hiredis Client 安装.Hiredis 是 Redis 官方指定的C语 ...
- Java:自动设置环境变量(转载)
引用: https://blog.csdn.net/qq_22498277/article/details/72149038 脚本下载地址:http://files.cnblogs.com/floww ...
- python 函数 动态参数 和嵌套
1.动态参数 是可以接收任意的参数.一种方式, 1,位置的动态传参, 写法是: *参数名 接收的参数是tuple类型举个例子:def yue(*food): print(food)yue(" ...
- python 基础 01
什么是计算机? cpu: 计算机的大脑; 读写速度 3GHZ 内存: (为了提高利用率) 缓冲硬盘和cpu 硬盘: 机械硬盘读写速度70mb/s 计算机里面读写的内容都是01代码 二进制(计算机只认二 ...
- Hystrix浅谈
Hystrix如何使用很多说明,看了很多博客,却发现能说明一些简单概念的文章就没有. 所以本文不太回去说如何使用 Hystrix ,但是会简明的说一下 一些概念 super(Setter.withGr ...
- pip的常用命令
前言 pip作为Python的御用包管理工具有着强大的功能,但是许多命令需要我们使用的时候借助搜索引擎查找(尤其是我), 于是我想将我使用到的命令整合下来,以后不用麻烦去找了,也希望能给你带来帮助.文 ...
- Python-爬虫-猫眼T100
目标站点需求分析 涉及的库 from multiprocessing import Poolfrom requests.exceptions import RequestExceptionimport ...
- Vue项目构建开发笔记(vue-lic3.0构建的)
1.router.js里面 { path: '/about', name: 'about', // route level code-splitting // this generates a sep ...
- android高级页面效果集锦
程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 一个强 ...