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. 静态网页怎样实现动态交互?-JavaScript

    在Html基础上,javascript能够开发交互式web网页.javascript的出现使得网页和用户之间实现了一种实时性的.动态的.交互性的关系,javascript短小精悍,又是在客户机上执行的 ...

  2. [LeetCode][Java] Subsets

    题目: Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset ...

  3. 九度OJ1004 Median

    题目描写叙述: Given an increasing sequence S of N integers, the median is the number at the middle positio ...

  4. Domino/Xpages Bootstrap 动态生成首页功能

    因为之前用户须要做个动态首页的功能,但一般用户又不熟HTML,所以最佳的方法能够使用拖动的方法来配置首页,一些主要的组件是已经帮用户的依据实际数据情况已经制作OK,用户仅仅须要简单配置就能够更改首页, ...

  5. 《TCP/IP具体解释》读书笔记(22章)-TCP的坚持定时器

    TCP通过让接收方指明希望从发送方接收的数据字节数(即窗体大小)来进行流量控制. 假设窗体大小为0会发生什么情况呢?这将有效阻止发送方传送数据,直到窗体变为非0为止. ACK的传输并不可靠,也就是说, ...

  6. 基于开源项目的在线网络视频直播项目---pc端的推流

    https://github.com/winlinvip/simple-rtmp-server/issues/66 https://github.com/justinmakaila/iOS-Frame ...

  7. 清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了

    使用360清理一下电脑垃圾,打开Eclipse发现左边的所有项目消失了,但在相应的workspace能够找到项目,这个问题已经是第三次遇到了(预计是被360清理掉Eclipse的一些部署或配置文件所导 ...

  8. 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) D.Dinner Bet 概率DP+排列组合

    题目链接:点这里 题意: 1~N标号的球 现在A有C个,B有C个 每次可以随机得到D个不同的球(1~N);问你A或B中的C个球都出现一次的 期望次数 题解: dp[i][j][k]表示 随机出现了i个 ...

  9. (17)会话之Cookie的使用详解

    Cooke技术 1,特点 Cookie技术:会话数据保存在浏览器客户端. 2,Cookie技术核心 Cookie类:用于存储会话数据  1)构造Cookie对象 Cookie(java.lang.St ...

  10. mysql03---触发器

    触发器trigger:某条数据改变,希望其他数据也改变(一张表的数据改变,另一张表的数据也变).监测insert,update,delete.能够监测增删改并出发增删改. 监测点(table)监测事件 ...