Codeforces 1096G. Lucky Tickets【生成函数】
题目大意
很简单自己看
思路
考虑生成函数(为啥tags里面有一个dp啊)
显然,每一个指数上是否有系数是由数集中是否有这个数决定的
有的话就是1没有就是0
然后求出这个生成函数的\(\frac{n}{2}\)次方
把每一项的系数全部平方加起来。。没了
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> Poly;
const int N = 3e6 + 10;
const int Mod = 998244353;
const int G = 3;
int add(int a, int b, int mod = Mod) {
return (a += b) >= mod ? a - mod : a;
}
int sub(int a, int b, int mod = Mod) {
return (a -= b) < 0 ? a + mod : a;
}
int mul(int a, int b, int mod = Mod) {
return 1ll * a * b % mod;
}
int fast_pow(int a, int b, int mod = Mod) {
int res = 1;
for (; b; b >>= 1, a = mul(a, a, mod))
if (b & 1) res = mul(res, a, mod);
return res;
}
int w[N][2];
void init() {
for (int i = 1; i < (1 << 21); i <<= 1) {
w[i][0] = w[i][1] = 1;
int wn = fast_pow(G, (Mod - 1) / (i << 1));
for (int j = 1; j < i; j++)
w[i + j][0] = mul(w[i + j - 1][0], wn);
wn = fast_pow(G, Mod - 1 - (Mod - 1) / (i << 1));
for (int j = 1; j < i; j++)
w[i + j][1] = mul(w[i + j - 1][1], wn);
}
}
void transform(int *t, int len, int typ) {
for (int i = 0, j = 0, k; j < len; j++) {
if (i > j) swap(t[i], t[j]);
for (k = (len >> 1); k & i; k >>= 1) i ^= k;
i ^= k;
}
for (int i = 1; i < len; i <<= 1) {
for (int j = 0; j < len; j += i << 1) {
for (int k = 0; k < i; k++) {
int x = t[j + k], y = mul(t[j + k + i], w[i + k][typ]);
t[j + k] = add(x, y);
t[j + k + i] = sub(x, y);
}
}
}
if (typ) return;
int invlen = fast_pow(len, Mod - 2);
for (int i = 0; i < len; i++)
t[i] = mul(t[i], invlen);
}
Poly fast_pow(Poly a, int b) {
int len = 1 << (int) ceil(log2(a.size()));
a.resize(len);
transform(&a[0], len, 1);
for (int i = 0; i < len; i++)
a[i] = fast_pow(a[i], b);
transform(&a[0], len, 0);
return a;
}
int n, k;
int main() {
init();
scanf("%d %d", &n, &k);
Poly a((int) 2e6);
for (int i = 1; i <= k; i++) {
int x;
scanf("%d", &x);
a[x] = 1;
}
a = fast_pow(a, n / 2);
int ans = 0;
for (int i = 0; i < (signed) a.size(); i++)
ans = add(ans, mul(a[i], a[i]));
printf("%d", ans);
return 0;
}
Codeforces 1096G. Lucky Tickets【生成函数】的更多相关文章
- 2019.01.26 codeforces 1096G. Lucky Tickets(生成函数)
传送门 题意简述:现在有一些号码由000~999中的某些数字组成(会给出),号码总长度为nnn,问有多少个号码满足前n2\frac n22n个数码的和等于后n2\frac n22n个数码的和(保证 ...
- Codeforces - 1096G - Lucky Tickets - NTT
https://codeforc.es/contest/1096/problem/G 把数组分成前后两半,那么前半部分的各个值的表示方案的平方的和就是答案. 这些数组好像可以dp出来. 一开始设dp[ ...
- @codeforces - 1096G@ Lucky Tickets
目录 @description@ @solution@ @accepted code@ @details@ @description@ 已知一个数(允许前导零)有 n 位(n 为偶数),并知道组成这个 ...
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- CF1096. G. Lucky Tickets(快速幂NTT)
All bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k dec ...
- DP+高精度 URAL 1036 Lucky Tickets
题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...
- Ural 1036 Lucky Tickets
Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...
- POJ 2346:Lucky tickets
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3247 Accepted: 2136 Des ...
随机推荐
- Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))
888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...
- 关于React性能优化
这几天陆陆续续看了一些关于React性能优化的博客,大部分提到的都是React 15.3新加入的PureComponent ,通过使用这个类来减少React的重复渲染,从而提升页面的性能.使用过Rea ...
- Unity另外一套简单日志控制系统
using UnityEngine; public class LogPrintf { static LogLevel logLevel = LogLevel.LOG_LEVEL_ERROR; pub ...
- Python 爬虫-图片的爬取
2017-07-25 22:49:21 import requests import os url = 'https://wallpapers.wallhaven.cc/wallpapers/full ...
- select exists 的应用一例
当遇到多层exists的时候,事情就变得开始复杂了.我们来看看这个例子吧 假设有三张表 选课表:学号.课程号 学生表:学号.姓名 课程表:课程号.课程名 请选出选了所有课程的学生 SELECT 姓名 ...
- Confluence 6 设置公共访问
你可以通过为匿名用户启用 'Use Confluence' 权限来启用匿名用户的站点访问(也称为公共访问) 一个匿名用户的定义为一个不需要登录就可以访问 Confluence 站点.使用 Conflu ...
- 富文本编辑器layedit,调用setContent方法会报错
需要把layedit.js里的setContent 函数的 layedit.sync(index)); 改成 this.sync(index));
- ORACLE中使用DBMS_SQL获取动态SQL执行结果中的列名和值
1.获取动态SQL中的列名及类型 DECLARE l_curid INTEGER; l_cnt NUMBER; l_desctab dbms_sql.desc_tab; l_sqltext ); BE ...
- laravel自定义分页功能的实现:
laravel版本:5.5.. 执行命令: php artisan vendor:publish --tag=laravel-pagination 在到 resources/views/vendor/ ...
- svn: E200009: 'lib/systemd/system/dropbear@.service': a peg revision is not allowed here problem
case: svn add lib/systemd/system/dropbear@.service svn: E200009: 'lib/systemd/system/dropbear@.servi ...