link

Description

懒得写了。

Solution

设 \(f(x)\) 表示对于一个位置操作了 \(x\) 次后刚好变为 \(1\) 的方案数,可以看出的是 \(f(x)\) 同样也是对于一个位置在操作了 \(x-1\) 次后仍没有变为 \(1\) 的方案数。

可以想到的是,第 \(i\) 个位置结束的方案数就是:

\[\sum_{x=0} f(x+1)^{i-1}f(x)^{k-i+1}
\]

考虑如何求 \(f(x)\) ,可以想到 \(f(x)\) 对应的是:有 \(m\) 种球,每种有 \(e_i\) 个,分到 \(x\) 个盒子中,不允许有盒子空着的方案数。设 \(g(x)=\prod_{i=1}^{m} \binom{e_i+x-1}{x-1}\),那么我们就可以容斥得到 \(f(x)\):

\[f(x)=\sum_{i=0}^{x} (-1)^{x-i}g(i)\binom{x}{i}
\]

直接卷就好了。

Code

#include <bits/stdc++.h>
using namespace std; #define Int register int
#define mod 985661441
#define MAXN 1000005 template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> inline void chkmax (T &a,T b){a = max (a,b);}
template <typename T> inline void chkmin (T &a,T b){a = min (a,b);} int up = 400000,fac[MAXN],ifac[MAXN]; int mul (int a,int b){return 1ll * a * b % mod;}
int dec (int a,int b){return a >= b ? a - b : a + mod - b;}
int add (int a,int b){return a + b >= mod ? a + b - mod : a + b;}
int qkpow (int a,int b){
int res = 1;for (;b;b >>= 1,a = mul (a,a)) if (b & 1) res = mul (res,a);
return res;
}
void Sub (int &a,int b){a = dec (a,b);}
void Add (int &a,int b){a = add (a,b);} int binom (int a,int b){return a >= b ? mul (fac[a],mul (ifac[b],ifac[a - b])) : 0;} #define SZ(A) ((A).size()) typedef vector<int> poly; int w[MAXN],rev[MAXN]; void init_ntt(){
int lim = 1 << 18;
for (Int i = 0;i < lim;++ i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << 17);
int Wn = qkpow (3,(mod - 1) / lim);w[lim >> 1] = 1;
for (Int i = lim / 2 + 1;i < lim;++ i) w[i] = mul (w[i - 1],Wn);
for (Int i = lim / 2 - 1;~i;-- i) w[i] = w[i << 1];
} void ntt (poly &a,int type){
#define G 3
#define Gi 328553814
static int d[MAXN];int lim = a.size();
for (Int i = 0,z = 18 - __builtin_ctz(lim);i < lim;++ i) d[rev[i] >> z] = a[i];
for (Int i = 1;i < lim;i <<= 1)
for (Int j = 0;j < lim;j += i << 1)
for (Int k = 0;k < i;++ k){
int x = mul (w[i + k],d[i + j + k]);
d[i + j + k] = dec (d[j + k],x),d[j + k] = add (d[j + k],x);
}
for (Int i = 0;i < lim;++ i) a[i] = d[i] % mod;
if (type == -1){
reverse (a.begin() + 1,a.begin() + lim);
for (Int i = 0,Inv = qkpow (lim,mod - 2);i < lim;++ i) a[i] = mul (a[i],Inv);
}
#undef G
#undef Gi
} poly operator * (poly A,poly B){
int lim = 1,l = 0,len = SZ(A) + SZ(B) - 1;
while (lim < SZ(A) + SZ(B)) lim <<= 1,++ l;
A.resize (lim),B.resize (lim),ntt (A,1),ntt (B,1);
for (Int i = 0;i < lim;++ i) A[i] = mul (A[i],B[i]);
ntt (A,-1),A.resize (len);
return A;
} poly operator * (poly a,int b){
for (Int i = 0;i < SZ(a);++ i) a[i] = mul (a[i],b);
return a;
} poly operator + (poly a,poly b){
int len = max (SZ(a),SZ(b));
a.resize (len),b.resize (len);
for (Int i = 0;i < len;++ i) Add (a[i],b[i]);
return a;
} poly operator - (poly a,poly b){
int len = max (SZ(a),SZ(b));
a.resize (len),b.resize (len);
for (Int i = 0;i < len;++ i) Sub (a[i],b[i]);
return a;
} poly operator + (poly a,int b){
Add (a[0],b);
return a;
} poly operator - (poly a,int b){
Sub (a[0],b);
return a;
} poly f; poly inv (poly &A,int n){
if (n == 1) return poly (1,qkpow (A[0],mod - 2));
poly Now,G0 = inv (A,(n + 1) >> 1);Now.resize (n);
for (Int i = 0;i < n;++ i)
if (i < SZ(A)) Now[i] = A[i];
else Now[i] = 0;
poly res = G0 * 2 - G0 * Now * G0;res.resize (n);
return res;
}
poly inv (poly A){return inv (A,SZ(A));} poly der (poly A){
for (Int i = 1;i < SZ(A);++ i) A[i - 1] = mul (A[i],i);
A.pop_back ();
return A;
} int getinv (int x){return mul (ifac[x],fac[x - 1]);}
poly inter (poly A){
A.push_back (0);
for (Int i = SZ(A) - 2;~i;-- i) A[i + 1] = mul (A[i],getinv (i + 1));
A[0] = 0;
return A;
} poly ln (poly a,int n){
poly res = inter (inv (a,n) * der (a));
res.resize (n);
return res;
}
poly ln (poly a){return ln (a,SZ(a));} void putout (poly a){
cout << SZ(a) << ": ";for (Int i = 0;i < SZ(a);++ i) cout << a[i] << " ";cout << endl;
} poly exp (poly &a,int n){
if (n == 1) return poly (1,1);
poly Now,G0 = exp (a,(n + 1) >> 1);Now.resize (n);
for (Int i = 0;i < n;++ i) Now[i] = a[i];
poly res = G0 - G0 * (ln(G0,n) - Now);res.resize (n);
return res;
}
poly exp (poly a){return exp (a,SZ(a));} int n,m,k,e[MAXN],p[MAXN];
void Work (){
n = 1;
for (Int i = 1;i <= m;++ i) read (p[i],e[i]),n += e[i];
poly F,G;F.resize (n + 1),G.resize (n + 1);
for (Int i = 1;i <= n;++ i){
int tmp = 1;
for (Int k = 1;k <= m;++ k) tmp = mul (tmp,binom (e[k] + i - 1,i - 1));
G[i] = mul (ifac[i],tmp);
}
for (Int i = 0;i <= n;++ i) F[i] = mul (ifac[i],i & 1 ? mod - 1 : 1);
// for (Int i = 0;i < SZ(F);++ i) cout << mul (fac[i],F[i]) << " ";cout << endl;
// for (Int i = 0;i < SZ(G);++ i) cout << mul (fac[i],G[i]) << " ";cout << endl;
F = F * G;
for (Int i = 0;i < SZ(F);++ i) F[i] = mul (F[i],fac[i]);
// for (Int i = 0;i < SZ(F);++ i) cout << F[i] << " ";cout << endl;
// cout << n << endl;
for (Int i = 1;i <= k;++ i){
int res = 0;
for (Int h = 0;h < n;++ h)
// cout << i << " , " << h << ": " << mul (qkpow (F[h + 1],i - 1),qkpow (F[h],k - i + 1)) << endl,
Add (res,mul (qkpow (F[h + 1],i - 1),qkpow (F[h],k - i + 1)));
write (res),putchar (' ');
}
putchar ('\n');
} signed main(){
init_ntt ();
fac[0] = 1;for (Int i = 1;i <= up;++ i) fac[i] = mul (fac[i - 1],i);
ifac[up] = qkpow (fac[up],mod - 2);for (Int i = up;i;-- i) ifac[i - 1] = mul (ifac[i],i);
int tot = 0;while (~scanf ("%d%d",&m,&k)) printf ("Case #%d: ",++ tot),Work ();
return 0;
}

题解 Division Game的更多相关文章

  1. 【题解】HDU5845 Best Division (trie树)

    [题解]HDU5845 Best Division (trie树) 题意:给定你一个序列(三个参数来根),然后请你划分子段.在每段子段长度小于等于\(L\)且子段的异或和\(\le x\)的情况下最大 ...

  2. Large Division(大数)题解

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  3. HDU3480:Division——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=3480 将一列数划分成几个集合,这些集合的并集为该数列,求每个数列的(最大值-最小值)^2的和的最小值. 简单的d ...

  4. December Challenge 2019 Division 1 题解

    传送门 当我打开比赛界面的时候所有题目都已经被一血了-- BINXOR 直接把异或之后二进制最多和最少能有多少个\(1\)算出来,在这个范围内枚举,组合数算一下就行了.注意\(1\)的个数是\(2\) ...

  5. CodeChef November Challenge 2019 Division 1题解

    传送门 AFO前的最后一场CC了--好好打吧-- \(SIMGAM\) 偶数行的必定两人平分,所以只要抢奇数行中间那个就行了 这题怎么被爆破了 //quming #include<bits/st ...

  6. Codechef July Challenge 2019 Division 1题解

    题面 \(CIRMERGE\) 破环成链搞个裸的区间\(dp\)就行了 //quming #include<bits/stdc++.h> #define R register #defin ...

  7. CF1444A (1445C)Division 题解

    题意:求最大的正整数 \(x\) ,使 \(x \mid p且q \nmid x\) . 首先,当 \(q \nmid p\) ,显然取 \(x=p\) 是最优解. 现在,我们考虑 \(q \mid ...

  8. Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 D题题解

    将题意转换为一开始\(t = 0\),第\(i\)个操作是令\(t \leftarrow (a_i + 1) t + (a_i + b_i + 1)\).记\(A_i = a_i + 1, B_i = ...

  9. Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 C题题解

    首先,我们将题目理解成若\(i\)与\(j\)距离恰好为\(3\),则不可能\(p_i \equiv p_j \equiv 1 \space or \space 2 (\bmod 3)\).这就相当于 ...

随机推荐

  1. 【SpringMVC】获取请求参数

    通过ServletAPI获取 test.html <a th:href="@{/testServletAPI(username='admin',password=123456)}&qu ...

  2. CPF 入门教程 - 各个控件介绍(八)

    CPF C#跨平台桌面UI框架 系列教程 CPF 入门教程(一) CPF 入门教程 - 数据绑定和命令绑定(二) CPF 入门教程 - 样式和动画(三) CPF 入门教程 - 绘图(四) CPF 入门 ...

  3. springgateway

    SpringGateAway: 先进行鉴权,然后进行路由,日志什么等等

  4. MMM双主-双从读写分离部署

    原文转自:https://www.cnblogs.com/itzgr/p/10233932.html作者:木二 目录 一 前期规划 1.1 主机规划 1.2 虚拟IP规划 1.3 用户列表 1.4 整 ...

  5. 存储系统管理(二)——Linux系统的swap分区、磁盘加密、磁盘阵列

    磁盘驱动器上的空间 , 用作当前未使用部分内存的溢出.这样 , 系统就能在主内存中留出空间用于储存当前正在处理的数据 , 并在系统面临主内存空间不足的风险时提供应急溢出. swap分区的建立: fdi ...

  6. Windows系统一些好用的办公工具

    在日常办公过程中,总有一些工具令人觉得方便,提高了工作效率.以下是根据我的习惯,收集了一些好用的工具,在此记录且不定期更新. 文件名 说明 Everything 文件搜索工具,搜索速度快 ALTRun ...

  7. PyQT5:信号和槽

    PyQT5:信号和槽 信号和槽 Qt的主要特征之一是它使用信号和插槽在对象之间进行通信. 当潜在的事件发生时,会发出一个信号.插槽是可调用的Python,如果将信号连接到插槽,则在发出信号时将调用该插 ...

  8. docker-compose up -d nginx 报错

    在阿里云ECS上创建nginx容器时,报错如上图. The solution: In your Dockerfile, before running any apt commands, add the ...

  9. 【HMS Core 6.0全球上线】Toolkit,您的智能辅助编程好帮手

    HMS Core 6.0已于7月15日全球上线.本次版本中,华为HMS Toolkit向广大开发者推出了智能辅助编程助手SmartCoder,帮助开发者轻松高效地集成HMS Core,开发新功能,创建 ...

  10. java版gRPC实战之三:服务端流

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...