Description

Transmission Gate

Solution

这一题可以考虑Dp,设\(Dp[i][j]\) 为在第i段中,以j颜色为结尾的最后一小段长度的最小值。

那么可以先考虑以表为结尾的情况:

  1. 表上一个线段的结尾,就把表看作分隔符,那么分隔符的数量下界是$lowerBound = \lceil \frac{(Dp[i - 1][j] + a[i])}{k} \rceil - 1 \(, 如果`b[i] > cnt`, 那么\)dp[i][j] = 1\(,上界\)upperBound$是a[i] * k

  2. 表是上一个线段的结尾, 分隔符数量下界是\(lowerBound = \lceil \frac{a[i]}{k} \rceil - 1\), 上界 $upperBound $ 是 \(a[i] * k + (k - Dp[i - 1][j ~ xor ~ 1])\)

    最后判断\(dp[n][0] \leq k || dp[n][1] \leq k\)

Summary

​ 刚开始设状态\(dp[i][j][l]\) 表示dp到ith段,段的最后颜色为j,这样的颜色在这一段的最后一部分有l长是否有解。 其实这样是不对的,算方案数判断是否可行的套路只适用于一些容斥数学题(eg. Mobius), 所以就多上一维的冗余信息。

​ 问题的模型是: 我们有n个段,段之间首尾相连,要求段中间的连续的隔板与球不超过k个。求是否有解。这样,我们不关心内部的排列方式, 并且内部排列不同不会影响下一段。这样的话我们可以直接考虑外部限制的情况下,钦定一种内部可行的方式。 而钦定就是对简单贪心的考察。

​ 因为上一段的影响对下一段越小,对解的限制也就越小(越容易出解),所以可以直接贪心。

​ 先考虑公式,将无关的公式看做挡板,表看作球。然后直接尽量容纳表即可。

Code

#include<bits/stdc++.h>
using std :: min;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
char ch = getchar();
int x = 0, flag = 1;
for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
return x * flag;
}
void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) write(x / 10);
putchar(x % 10 + 48);
} const int Maxn = 3e5 + 9;
static int dp[Maxn][2], n;
static int x[Maxn], y[Maxn], k; void init() {
n = read(), k = read();
rep (i, 1, n) x[i] = read();
rep (i, 1, n) y[i] = read();
} int getCalc(int preVal, int preSeparator, int nowVal, int nowSeparator) {
int res = 0x3f3f3f3f;
if (preVal < 0x3f3f3f3f) {
LL lowerBound = ceil((1ll * preVal + nowVal) * 1. / k) - 1;
if (nowSeparator < lowerBound) res = min(res, 0x3f3f3f3f);
else if (nowSeparator > 1ll * nowVal * k) res = min(res, 0x3f3f3f3f);
else if (nowSeparator > lowerBound) res = min(res, 1);
else res = min(1ll * res, (1ll * preVal + nowVal) % k ? (1ll * preVal + nowVal) % k : k);
} if (preSeparator < 0x3f3f3f3f) {
LL lowerBound = ceil(nowVal * 1. / k) - 1;
if (nowSeparator < lowerBound) res = min(res, 0x3f3f3f3f);
else if (nowSeparator > 1ll * (nowVal - 1) * k + (k - preSeparator)) res = min(res, 0x3f3f3f3f);
else if (nowSeparator > lowerBound) res = min(res, 1);
else res = min(1ll * res, (1ll * nowVal) % k ? (1ll * nowVal) % k : k);
}
return res;
} void solve() {
dp[0][0] = 0; dp[0][1] = 0; rep (i, 1, n) {
dp[i][0] = getCalc(dp[i - 1][0], dp[i - 1][1], x[i], y[i]);
dp[i][1] = getCalc(dp[i - 1][1], dp[i - 1][0], y[i], x[i]);
} puts(dp[n][0] <= k || dp[n][1] <= k ? "YES" : "NO");
} int main() { init();
solve(); #ifdef Qrsikno
debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
return 0;
}

[CF1076F] Summer Practice Report的更多相关文章

  1. Codeforces 1076F Summer Practice Report dp

    Summer Practice Report dp[ i ][ 0 ]表示放完前 i 页, 第 i 页最后一段是 0, 0个数的最小值. dp[ i ][ 1 ]表示放完前 i 页, 第 i 页最后一 ...

  2. Codeforces1076F. Summer Practice Report(贪心+动态规划)

    题目链接:传送门 题目: F. Summer Practice Report time limit per test seconds memory limit per test megabytes i ...

  3. Educational Codeforces Round 54 (Rated for Div. 2) Solution

    A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...

  4. Codeforces Educational Codeforces Round 54 题解

    题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...

  5. BA Practice Lead Handbook 1 - Why Is Business Analysis Taking The World By Storm?

    The articles in this series are focused on individual Business Analysts and their managers. https:// ...

  6. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  7. Atitit 数据存储视图的最佳实际best practice attilax总结

    Atitit 数据存储视图的最佳实际best practice attilax总结 1.1. 视图优点:可读性的提升1 1.2. 结论  本着可读性优先于性能的原则,面向人类编程优先于面向机器编程,应 ...

  8. 2.ASP.NET MVC 中使用Crystal Report水晶报表

    上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...

  9. Monthly Income Report – August 2016

    原文链接:https://marcoschwartz.com/monthly-income-report-august-2016/ Every month, I publish a report of ...

随机推荐

  1. Input系统—ANR原理分析(转)

    一. 概述 当input事件处理得慢就会触发ANR,那ANR内部原理是什么,哪些场景会产生ANR呢. “工欲善其事必先利其器”,为了理解input ANR原理,前面几篇文章疏通了整个input框架的处 ...

  2. oracle随机数

    1.从表中随机取记录 select * from (select * from staff order by dbms_random.random) where rownum < 4 表示从ST ...

  3. URL编码总结

    URL编码总结           URL是Universal Resource Locator的简称.翻译过来那就是统一资源定位符,好吧,我们常常会俗称为网页地址. 一个URL的格式一般是这种:协议 ...

  4. Tcl学习之--列表|字典

    [列表|字典] Tcl使用列表来处理各种集合,比方一个目录中的全部文件,以及一个组件的全部选项.最简单的列表就是包括由随意个空格.制表符.换行符.分隔的随意多个元素的字符串.比方: JerryAlic ...

  5. EditText设置光标位置问题

    普通设置 EditText 光标显示位置的方法就是 et.setSelection(text.length()); et.setSelection(0); 设置0 就是第一位了. 设置text长度就最 ...

  6. 【iOS9系列】-3DTouch开发

    [iOS9系列]-3DTouch开发 第一:简介 3DTouch 是iOS9系统系统下,在iPhone6s(iPhone6s Plus)手机上才能够使用的功能.熟练使用后,发现还是很便捷的. 但是模拟 ...

  7. Datagrid接收JSON数据格式

    开打View下面的Shared创建一个视图模版(母版页)<!DOCTYPE html> <html> <head> <title>Main</ti ...

  8. ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp

    Seven Segment Display Time Limit: 1 Second      Memory Limit: 65536 KB A seven segment display, or s ...

  9. Poisson distribution 泊松分布 指数分布

    Poisson distribution - Wikipedia https://en.wikipedia.org/wiki/Poisson_distribution Jupyter Notebook ...

  10. windows 目录空格

    Window下安装Scala出现:此时不应有 \scala\bin\..\lib\jline-2.14.5.jar 原因很简单,scala默认安装到了Program Files (x86)文件夹下,目 ...