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. wpf窗口阴影

    https://www.cnblogs.com/yiyan127/p/6362509.html

  2. LeetCode--088--合并两个有序数组

    方法1: class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: Li ...

  3. Asp.Net中的sessionState设置

    在web.config中有sessionState的节点配置,sessionState共有4中模式:off,inProc,StateServer,SqlServer. 1. off模式 关闭模式,如果 ...

  4. python-day52--前端html、css

    一.html需掌握的: 1. img标签 属性:src alt title width height 2. a标签 属性:href target 3. ul 标签及li 标签,二者都是块级标签 ul ...

  5. SQL Server日志清空方法

    1.清空日志:DUMP   TRANSACTION   databasename   WITH   NO_LOG 2.截断事务日志:BACKUP   LOG   databasename   WITH ...

  6. python运维之使用python进行批量管理主机

    1. python运维之paramiko 2. FABRIC 一个与多台服务器远程交互的PYTHON库和工具 3. SSH连接与自动化部署工具paramiko与Fabric 4. Python批量管理 ...

  7. 白化whitening

    原文地址:http://blog.csdn.net/hjimce/article/details/50864602 作者:hjimce 一.相关理论     白化这个词,可能在深度学习领域比较常遇到, ...

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

  9. Android中aar和jar文件的认识

    在Android开发中,我们总是会引入其他第三方的库或者资源等,有时候是添加一个jar文件,有时候添加一个aar文件,那么这两种类型的文件有什么区别吗?详情请看下文. 一.描述. 1.   *.jar ...

  10. Java——文件过滤器

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...