Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)
这线段期望好神啊。。。
还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客
本蒟蒻只会O(n2)O(n^2)O(n2)
CODE
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef long long LL;
const int MAXN = 4005;
inline void add(int &x, int y) { x += y; if(x >= mod) x -= mod; }
inline int qpow(int a, int b) {
int res = 1;
while(b) {
if(b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod; b >>= 1;
}
return res;
}
int n, l, k, f[2][MAXN][2];
int main () {
scanf("%d%d%d", &n, &k, &l);
int now = 0, N = 2*n+1;
f[0][0][0] = 1;
for(int i = 1; i <= N; ++i) {
now ^= 1; memset(f[now], 0, sizeof f[now]);
for(int j = 0; j < i; ++j) {
add(f[now][j+1][0], f[now^1][j][0]),
add(f[now][j+1][1], f[now^1][j][1]);
if(j)
add(f[now][j-1][0], 1ll * f[now^1][j][0] * j % mod),
add(f[now][j-1][1], 1ll * f[now^1][j][1] * j % mod);
if(j >= k)
add(f[now][j][1], f[now^1][j][0]);
}
}
int ans = 1ll * f[now][0][1] * l % mod * qpow(2, n) % mod;
for(int i = n+1; i <= N; ++i) ans = 1ll * ans * qpow(i, mod-2) % mod;
printf("%d\n", (ans + mod) % mod);
}
Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)的更多相关文章
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目链接 题意:给你一个有根树,假设有k个叶子节点,你可以给每个叶子节点编个号,要求编号不重复且在1-k以内.然后根据节点的max,minmax,minmax,min信息更新节点的值,要求根节点的值最 ...
- Codeforces Round #551 (Div. 2) D. Serval and Rooted Tree (树形dp)
题目:http://codeforces.com/contest/1153/problem/D 题意:给你一棵树,每个节点有一个操作,0代表取子节点中最小的那个值,1代表取子节点中最大的值,叶子节点的 ...
- Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)
https://codeforces.com/contest/1080/problem/F 题意 有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b ...
- Codeforces Round #346 (Div. 2)---E. New Reform--- 并查集(或连通图)
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory lim ...
- Codeforces Round #524 (Div. 2) C. Masha and two friends(矩形相交)
C. Masha and two friends time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #551 (Div. 2)A. Serval and Bus
A. Serval and Bus time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #551 (Div. 2)B. Serval and Toy Bricks
B. Serval and Toy Bricks time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #551 (Div. 2) E. Serval and Snake (交互题)
人生第一次交互题ac! 其实比较水 容易发现如果查询的矩阵里面包含一个端点,得到的值是奇数:否则是偶数. 所以只要花2*n次查询每一行和每一列,找出其中查询答案为奇数的行和列,就表示这一行有一个端点. ...
- Codeforces Round #509 (Div. 2) F. Ray in the tube(思维)
题目链接:http://codeforces.com/contest/1041/problem/F 题意:给出一根无限长的管子,在二维坐标上表示为y1 <= y <= y2,其中 y1 上 ...
随机推荐
- redis实战---读书笔记
第一章 初识redis redis 是一个远程内存数据库,性能强劲,具有复制特性以及为解决问题而生的独一无二的数据模型. 1. redis 简介 redis 是一种非关系型数据库(NOSQL) r ...
- mysql只会使用到一个索引的原因
select count(1) from table1 where column1 = 1 and column2 = 'foo' and column3 = 'bar' 其中column1,colu ...
- Java Web 深入分析(5) Java ClassLoader 工作机制
Classloader 有3个作用 将class加载到JVM中去 审查每个类由谁去加载,是一种父优先的等级加载 把Class字节码统一编译成JVM统一要求的对象格式 ClassLoader的等级加载机 ...
- Python练习_高阶函数_day11
1,写函数,传入n个数,返回字典{‘max’:最大值,’min’:最小值} 例如:min_max(2,5,7,8,4) 返回:{‘max’:8,’min’:2}(此题用到max(),min()内置函数 ...
- 函数实现计算等差数列的第n项
等差数列的第n项 描述 等差数列是指从第二项起,每一项与它的前一项的差等于同一个常数的一种数列,这个常数叫做等差数列的公差. ...
- springboot mvc自动配置(三)初始化mvc的组件
所有文章 https://www.cnblogs.com/lay2017/p/11775787.html 正文 在springboot mvc自动配置的时候,获得了DispatcherServlet和 ...
- CVE-2018-2879 - anniversary
For the anniversary of the discovery of CVE-2018-2879 by Sec Consult (https://sec-consult.com/en/blo ...
- Go 结构体的使用
结构体是用户定义的类型,表示若干个字段(Field)的集合.有时应该把数据整合在一起,而不是让这些数据没有联系.这种情况下可以使用结构体. 例如,一个职员有 firstName.lastName 和 ...
- 自定义centos
目录 自定义centos 1. 为什么要自定义centos 2. 自定义centos步骤 自定义centos 1. 为什么要自定义centos 在使用官网的 centos镜像,只有200m,很小,但是 ...
- Marketing Cloud的contact merge机制
Marketing Cloud的contact支持多种多样的数据源,如下图所示: SAP Hybris Commerce SAP ERP SAP Cloud for Customer SAP Gigy ...