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. webpack编译后的代码如何在浏览器执行

    浏览器是无法直接使用模块之间的commonjs或es6,webpack在打包时做了什么处理,才能让浏览器能够执行呢,往下看吧. 使用commonjs语法 先看下写的代码, app.js minus.j ...

  2. 细说Typescript类型检查机制

    上一篇文章我介绍了Typescript的基础知识,回顾一下,有基础数据类型.数组.函数.类.接口.泛型等,本节内容将述说一下Typescript为方便我们开发提供了一些类型检查机制. 类型检查机制 类 ...

  3. minicom-linux下USB转串口配置

    现在的笔记本越做越薄,好些电脑已经没有串口了,做硬件开发会非常头疼,不过有了USB转串口设备,PC机只需要有USB接口就可以了.在linux下我们使用minicom与目标设备通信,在此记录一下linu ...

  4. JMeter中使用交替控制器设置循环次数后都执行一次?

    JMeter在线程组设置循环3次,执行后只执行了一次就停止执行了 排查原因:线程组下添加了一些请求信息(HTTP Cache Manager.HTTP Cookie Manager.HTTP Requ ...

  5. VS dll 引用依赖

    在公司实习过程中,经常遇到三个问题: 开发环境 dll引用依赖 dll版本控制 一般公司都会配置开发/测试/Lab/线上四个环境,之后不管时开发什么项目,都与环境分不开边.这个和dll版本控制暂且记下 ...

  6. 20210803 noip29

    考场 第一次在 hz 考试.害怕会困,但其实还好 看完题感觉不太难,估计有人 AK. T3 比较套路,没办法枚举黑点就从 LCA 处考虑,在一个点变成黑点时计算其他点和它的 LCA 的贡献,暴力跳父亲 ...

  7. Vue element keyup.enter失效不起作用

    解决方式一 添加按键修饰符@keyup.enter.native 解决方式二 把事件绑定到父元素(外框),需注意多个input问题 <div @keyup.enter="login&q ...

  8. Vue3 父组件调用子组件的方法

    Vue3 父组件调用子组件的方法 // 父组件 <template> <div> 父页面 <son-com ref="sonRef"/> < ...

  9. 双非Java的学习之旅以及秋招路程

    个人信息: 趁着中秋写个帖子记录一下吧.渣渣本,无实习,无高质量证书,走了很多弯路,最后选择的Java后端.现在算是半躺平了,接了几个中小厂的offer保底,20w多的薪资,后面还有几家公司接着面.不 ...

  10. Java实现导出Excel

    项目中实现的代码: 一.//controller @RequestMapping(value = "/exportAccountManager") public void expo ...