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. Go和HTTPS(TLS)

    原文链接: http://studygolang.com/wr?u=http%3a%2f%2ftonybai.com%2f2015%2f04%2f30%2fgo-and-https%2f 近期在构思一 ...

  2. Intellij IDEA远程调试tomcat

    1.windows系统 文件catalina.bat首行增加下面代码 set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE ...

  3. ART虚拟机之Trace原理(转)

    一.概述 Android 6.0系统采用的art虚拟机,所有的Java进程都运行在art之上,当应用发生ANR(Application Not Response,其中最终的一个环节便是向目标进程发送信 ...

  4. 我的package.json清单

    { "name": "lists", "version": "1.0.0", "main": &qu ...

  5. Linux学习笔记:系统启动引导过程

    Linux系统启动引导过程 近期发现自己在仅仅是掌握上有几个比較硬的伤: 一.知识体系碎片,比方Linux,这学点那学点,结果没有成体系,串不起来: 二.记忆时间短暂,非常多的内容学了就忘,最后的结果 ...

  6. HDU1251 统计难题 【trie树】

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  7. HTTP要点概述:四,HTTP方法

    使用HTTP协议的时候,客户端可以通过HTTP方法告知服务器自己请求的意图. 看了这篇文章以后,谁再说HTTP方法只有GET和POST,你的眼睛是用来吃饭的嘛! 一,GET:获取资源 GET用来请求访 ...

  8. mybatis批量操作数据

    批量查询语句: List<MoiraiProductResource> selectBatchInfo(List<Long> idList); <!-- 批量查询 --& ...

  9. 用 kGDB 调试 Linux 内核

    简介 这个文档记录了用kGDB调试Linux内核的全过程,都是在前人工作基础上的一些总结.以下操作都是基于特定板子来进行,但是大部分都能应用于其他平台. 要使用KGDB来调试内核,首先需要修改conf ...

  10. 1.ARC下是否有内存溢出等问题 2.@property参数 3.#import和@class的区别

    1.ARC下是否有内存溢出等问题? 答案:必须要担心啊,ARC也不是万能的.答案:必须要担心啊,ARC也不是万能的.这里主要是涉及到集合类的数据类型   比如数组,我们定义了一个可变数组muarr1, ...