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 上 ...
随机推荐
- Azure经典虚拟机(Windows)如何监测单个磁盘的使用空间
Azure云平台创建经典虚拟机(Windows)后,发现仪表板的监测项下默认是没有针对磁盘空间进行检测的指标的 本地机器安装Windows Azure Powershell模块,并通过如下命令登陆并查 ...
- Google 安装 Elasticsearch-head 插件
下载插件:https://github.com/liufengji/es-head 安装插件: google --->更多工具---->扩展程序 将解压的elasticsearch-hea ...
- (六)Cookie 知识点总结 (来自那些年的笔记)
如果你想要转载话,可不可以不要删掉下面的 作者信息 呀!: 作者:淮左白衣 写于 2018年4月18日18:47:41 来源笔者自己之前学javaWeb的时候,写的笔记 : 目录 如果你想要转载话,可 ...
- Word 插入目录的 5 种方法
1. "运用多级编号法"之图文教程 效果图: 步骤: 首先,为了更好的演示,我们先将我们的一级标题全部选中,按住Ctrl键,去一一选择就行了. 选中一级标题后,我们进入「开始」-「 ...
- 【学习笔记】RMQ-Range Minimum/Maximum Query (区间最小/最大值)
RMQ是一类询问区间最小/最大值的问题. 这类问题一般分成两类:静态区间(无修改),动态区间(带修改). 对于动态区间查询最大/最小,我们显然可以用线段树来解决…… 那么对于静态区间查询最大/最小的问 ...
- python中传统除法、真除法和Floor除法
1.python2.6及其之前,x/y是传统除法,对于整数会省去小数部分,对于浮点数会保持小数部分. 2.python3中x/y表示真除法,无论任何数据类型都会保留小数部分. 3.python2和3中 ...
- python第一个浏览器的自动执行程序
1.目标:简单点,百度搜索“美丽的程序员” 2.操作方法: a.python已经安装完成 b.安装PIP:在windows的cmd窗口下输入easy_install pip c.安装sele ...
- python学习-48 模块2
sys修改环境变量 ---------- 只能临时修改 import syssys.path.append() 例如: import sys sys.path.append('C:\Users\hua ...
- LIUNX随堂学习-3 权限
1.权限分为三类:读r,写w,执行x 2.读r:可以ls改目录下的子文件名,子目录名 写w:可以在该目录下创建.删除.重命名 执行x:可以cd到该目录下 3. ll (ls -l) 下详细信息的意义 ...
- C++ std::string 在一个字符串前插入一个字符串几种方式
目录 1.直接使用字符串相加 2.使用insert函数 比较:通过Quick C++ Benchmarks 可得到结果 1.直接使用字符串相加 std::string a = "hello& ...