I-Just Jump_2019牛客暑期多校训练营(第八场)
题目链接
题意
有L+1个点,初始在第0个点上,要跳到第L个点,每次至少跳d格,也就是在点x至少要跳到x+d,且有m个限制
\((t_i, p_i)\)指跳第\(t_i\)次不能跳到\(p_i\)上
题解
设dp[i]表示从0跳到i且没有限制的方案数,可以预处理。对限制按t从小到大排序,\(g[i][0]\)表示通过了前i-1个限制,踩在了第i个限制上且1-i这些限制踩了偶数个,\(g[i][1]\)表示踩了奇数个限制的方案数,可以\(m^2\)递推,根据容斥原理加上踩偶次的方案数扣掉踩奇数次的方案数。
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 1e7+5;
const int mod = 998244353;
ll dp[mx], fac[mx], invf[mx];
int g[3005][2];
int L, d, m;
int pow_mod(ll a, ll b) {
ll ans = 1;
while (b > 0) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans;
}
struct Node {
int t, p;
bool operator < (Node other) const {
return t < other.t;
}
}node[3005];
int C(int x, int y) {
if (x < y || y < 0 || x < 0) return 0;
return (1LL * fac[x] * invf[y] % mod * invf[x-y]) % mod;
}
int calc(int i, int j) {
if (1LL * (node[j].t-node[i].t)*d > node[j].p-node[i].p) return 0;
return C(node[j].p-node[i].p-(node[j].t-node[i].t)*d + (node[j].t-node[i].t) - 1, node[j].t-node[i].t-1);
}
int main() {
scanf("%d%d%d", &L, &d, &m);
for (int i = 1; i <= m; i++) scanf("%d%d", &node[i].t, &node[i].p);
sort(node+1, node+1+m);
node[0].t = node[0].p = 0;
dp[0] = 1;
int sum = 0;
for (int i = 1; i <= L; i++) {
if (i-d >= 0) sum = (sum + dp[i-d]) % mod;
dp[i] = sum;
}
fac[0] = invf[0] = 1;
for (int i = 1; i <= L; i++) fac[i] = 1LL * fac[i-1] * i % mod;
invf[L] = pow_mod(fac[L], mod-2);
for (int i = L-1; i >= 1; i--) invf[i] = 1LL * invf[i+1] * (i+1) % mod;
g[0][0] = 1; g[0][1] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 0; j < i; j++) {
g[i][0] = (g[i][0] + 1LL * g[j][1] * calc(j, i) % mod) % mod;
g[i][1] = (g[i][1] + 1LL * g[j][0] * calc(j, i) % mod) % mod;
}
}
ll ans = dp[L];
for (int i = 1; i <= m; i++) {
ans += 1LL * (g[i][0] - g[i][1]) * dp[L-node[i].p] % mod;
ans = (ans % mod + mod) % mod;
}
printf("%lld\n", ans);
return 0;
}
I-Just Jump_2019牛客暑期多校训练营(第八场)的更多相关文章
- 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)
题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9: 对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可. 后者mod=1e9,5才 ...
- 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...
- 2019牛客暑期多校训练营(第一场) B Integration (数学)
链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...
- 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...
- 2019牛客暑期多校训练营(第二场)F.Partition problem
链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...
- 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)
链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...
- [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem
链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...
- 2019牛客暑期多校训练营(第二场)J-Subarray(思维)
>传送门< 前言 这题我前前后后看了三遍,每次都是把网上相关的博客和通过代码认真看了再思考,然并卵,最后终于第三遍也就是现在终于看懂了,其实懂了之后发现其实没有那么难,但是的的确确需要思维 ...
- J-Subarray_2019牛客暑期多校训练营(第二场)
题意 有一个只由1,-1组成的数组,给出所有连续的1所在位置,求满足1的个数大于-1的个数的子区间的数量 题解 参考博客:https://www.cnblogs.com/Yinku/p/1122149 ...
随机推荐
- Chrome 使用 Evernote 插件
Chrome 插件不能登印象笔记进行裁剪,被困扰有段时间了.昨天偶然在知乎上找到了解决方法: 链接:https://www.zhihu.com/question/20340803/answer/291 ...
- 我的ubuntu kylin中mentohust的使用历程
1首先下载mentohus 最新版下载(包括源码):http://code.google.com/p/mentohust/downloads/list 2打开终端(Ctrl+Alt+T) 输入sudo ...
- dubbo异常处理
dubbo异常处理 我们的项目使用了dubbo进行不同系统之间的调用. 每个项目都有一个全局的异常处理,对于业务异常,我们会抛出自定义的业务异常(继承RuntimeException). 全局的异常处 ...
- S2:面向对象
面向对象七大设计原则 1. 开闭原则 2. 里氏替换原则 3. 单一职责原则 4. 接口隔离原则 5. 依赖倒置原则 6. 迪米特原则 7.组合/聚合复用原则 原则一:(SRP:Single resp ...
- MySQL操作命令梳理(2)
一.表操作 在mysql运维操作中会经常使用到alter这个修改表的命令,alter tables允许修改一个现有表的结构,比如增加或删除列.创造或消去索引.改变现有列的类型.或重新命名列或表本身,也 ...
- Okhttp3 网络请求框架与 Gson
Maven环境 : <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>o ...
- centos开发环境安装
执行 yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel ...
- ubuntu安装伪分布式Hadoop3.1.2
作业要求:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3223 本文是基于已经安装好的ubuntu环境上搭建伪分布式hadoop,在 ...
- vscode c 语言 win10
在看 CSAPP 一些课程,一些c 语言的小程序的例子,想跑起来试试,用一个DEV c++ 简单上手,但这是一个上古的IDE, 前端开发中的代码不全,语法高亮,都不太好,就想着为什么不折腾一下 V ...
- hadoop开启Service Level Authorization 服务级认证-SIMPLE认证-过程中遇到的坑
背景描述: 最近在进行安全扫描的时候,说hadoop存在漏洞,Hadoop 未授权访问[原理扫描],然后就参考官方文档及一些资料,在测试环境中进行了开启,中间就遇到了很多的坑,或者说自己没有想明白的问 ...