LINK

题目大意

很简单自己看

思路

考虑生成函数(为啥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【生成函数】的更多相关文章

  1. 2019.01.26 codeforces 1096G. Lucky Tickets(生成函数)

    传送门 题意简述:现在有一些号码由000~999中的某些数字组成(会给出),号码总长度为nnn,问有多少个号码满足前n2\frac n22n​个数码的和等于后n2\frac n22n​个数码的和(保证 ...

  2. Codeforces - 1096G - Lucky Tickets - NTT

    https://codeforc.es/contest/1096/problem/G 把数组分成前后两半,那么前半部分的各个值的表示方案的平方的和就是答案. 这些数组好像可以dp出来. 一开始设dp[ ...

  3. @codeforces - 1096G@ Lucky Tickets

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 已知一个数(允许前导零)有 n 位(n 为偶数),并知道组成这个 ...

  4. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  5. POJ-2346 Lucky tickets(线性DP)

    Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...

  6. 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 ...

  7. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  8. Ural 1036 Lucky Tickets

    Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...

  9. POJ 2346:Lucky tickets

    Lucky tickets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3247   Accepted: 2136 Des ...

随机推荐

  1. Python 爬虫-正则表达式(补)

    2017-08-08 18:37:29 一.Python中正则表达式使用原生字符串的几点说明 原生字符串和普通字符串的不同 相较于普通字符串,原生字符串中的\就是反斜杠,并不表达转义.不过,字符串转成 ...

  2. C#使用xpath查找xml节点信息

    Xpath是功能很强大的,但是也是相对比较复杂的一门技术,最好还是到博客园上面去专门找一些专业的帖子来看一看,下面是一些简单的Xpath语法和一个实例,提供给你参考一下. xml示例: <?xm ...

  3. 使用MyBatis Generator自动生成实体、mapper和dao层

    原文链接 通过MyBatis Generator可以自动生成实体.mapper和dao层,记录一下怎么用的. 主要步骤: 关于mybatis从数据库反向生成实体.DAO.mapper: 参考文章:ht ...

  4. [Java学习] Java Object类

    Object 类位于 java.lang 包中,是所有 Java 类的祖先,Java 中的每个类都由它扩展而来. 定义Java类时如果没有显示的指明父类,那么就默认继承了 Object 类.例如: 1 ...

  5. 使用Laravel提交POST请求出现The page has expired due to inactivity错误

    任何指向 web 中 POST, PUT 或 DELETE 路由的 HTML 表单请求都应该包含一个 CSRF 令牌(CSRF token),否则,这个请求将会被拒绝.

  6. nyoj-310-河南省第四届省赛题目-二分+dinic

    SECRET 时间限制:3000 ms  |  内存限制:65535 KB 难度:6   描述 Dr.Kong is constructing a new machine and wishes to ...

  7. iOS UI-手势(Gesture)

    #import "ViewController.h" @interface ViewController ()<UIActionSheetDelegate> @prop ...

  8. node -- hapi 学习

    node learning 学习node,是为了后续项目可以正常开展,现在写个项目,若不是连接后台,请求数据,一切都不叫着项目了.正好借助掘金的小册,来推进学习 学习资料 YouTube 1 掘金 h ...

  9. React Js 之JSX

    React使用JSX作为模板替换JavaScript,它不是必须的,但是它是推荐使用.原因如下: 1.它比传统的JavaScript更快,因为编译代码的时候,JSX做了相应的优化 2.它是类型安全的, ...

  10. Vysor安装图解

    Vysor安装图解   11 准备东西       路径 C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default   ...