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 ...
随机推荐
- case和decode的用法(行转列)
创建了一张成绩表,如下图所示: 在oracle中,这两个函数我们都可以使用,代码及结果如下: decode用法: select Name,decode(Subject,'语文',1,'数学',2,'英 ...
- C#使用OLEDB方式读取EXCEL,表的结构
var tables = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { }); Ta ...
- Shiro权限框架与SpringMVC集成
1.Shiro整合SpringMVC 我们学习Shiro框架肯定是要应用到Web项目上的,所以我们需要整合Shiro和SpringMVC 整合步骤: 第一步:SpringMVC框架的配置 spring ...
- Spring Boot简单环境搭建
#### 一.创建一个简单的Maven项目 使用`Maven`,通过导入`Spring Boot`的`starter`模块,可以将许多程序依赖的包自动导入到工程中.使用`Maven`的`parent ...
- 如何在docker下安装elasticsearch(上)
一 环境 VMware® Workstation 15 Pro centos7 (1810) docker19.03.1 二 进入centos7启动dcoker systemctl start doc ...
- Dialog 使用详解
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- Go orm框架gorm学习
之前咱们学习过原生的Go连接MYSQL的方法,使用Go自带的"database/sql"数据库连接api,"github.com/go-sql-driver/mysql& ...
- 简洁实用Socket框架DotNettySocket
目录 简介 产生背景 使用方式 TcpSocket WebSocket UdpSocket 结尾 简介 DotNettySocket是一个.NET跨平台Socket框架(支持.NET4.5+及.NET ...
- HTML5标签的使用和作用
在菜鸟教程中找了一些关于HTML5的知识点,觉得很有用,可以整理一下,以后使用. 这是一个基本的HTML5文档: <!DOCTYPE html><html><head&g ...
- 洛谷 P1903 [国家集训队]数颜色
题意简述 给定一个数列,支持两个操作 1.询问l~r有多少不同数字 2.修改某个数字 题解思路 带修莫队 如果修改多了,撤销修改 如果修改少了,进行修改 代码 #include <cmath&g ...