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 ...
随机推荐
- Thunder团队Final版本控制
Final版本控制报告 团队介绍:Thunder Check in次数 :6次. check in log(时间.人员.message.动机.其他解释) 代码贡献量.代码贡献比例以及代码作用 git链 ...
- js 文件上传
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- MINA2.0用户手册中文版
MINA2.0用户手册中文版--第一章 MINA2.0入门 MINA2.0用户手册中文版--第二章 第一节 MINA应用程序架构 MINA2.0用户手册中文版--第二章 第二节 TCP服务端实例 MI ...
- angular5 表单元素 checkbox radio 组讲解
一.checkedbox 1.ngModel绑定方式 <input [(ngModel)]="item.checked" value="item.checked&q ...
- 雷林鹏分享:Ruby 类和对象
Ruby 类和对象 Ruby 是一种完美的面向对象编程语言.面向对象编程语言的特性包括: 数据封装 数据抽象 多态性 继承 这些特性将在 面向对象的 Ruby 中进行讨论. 一个面向对象的程序,涉及到 ...
- 问题✅:render json的格式支持。to_json被改成as_json,功能一样
class StudentsController < ApplicationController def show @student = Student.find(params[:id]) re ...
- codeforces 516c// Drazil and Park// Codeforces Round #292(Div. 1)
题意:一个圆环上有树,猴子上下其中一棵树,再沿着换跑,再上下另一棵树.给出一个区间,问最大的运动距离是. 给出区间大小dst,和数高数组arr. 设区间[x,y],a[x]=2*arr[x]+dst[ ...
- JS-构造函数2
一.如何创建对象 1.对象字面量 var obj1={ name:"吻别", singer:"张学友", type:"流行" } 2.构造函 ...
- Leetcode 113
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- Leetcode 784
//这代码可真丑陋,但我学到了两点1:char和string可以无缝互相转换2:char可以直接加减数字进行转换string不行 class Solution { public: vector< ...