原题链接:Paperfolding
题面:
题目大意:
给你一张纸,可以进行四种操作,向上向下向左向右对折,实际上向上向下为一种,即竖直对折;向左向右一种,即水平对折。对折完后可以进行横竖一刀切的操作,将纸张分成
s
s
s 张。
现在给定一个
n
n
n,问经过
n
n
n 次四种操作后,期望
E
(
s
)
E(s)
E(s) ,即最终切割后得到的纸张数
s
s
s 的期望是多少。
数学推导:
用纸张模拟 (我脑子不太好使,撕了几张纸)。
可以发现,水平和竖直的对折,对于结果的影响都是独立的,即水平对折只影响水平的切痕,竖直的对折只影响竖直的切痕。
如果进行了
x
x
x 次水平对折和
y
y
y 次竖直对折。
此时相当于对于一张纸张进行了
2
x
2^x
2x 次水平切割,
2
y
2^y
2y 次竖直切割。
最终获得的纸张数量是:
(
2
x
+
1
)
∗
(
2
y
+
1
)
(2^x+1)*(2^y+1)
(2x+1)∗(2y+1)。
所以最终的期望为: E ( s ) = 1 2 n ∗ ∑ i = 0 n C ( n , i ) ( 2 i + 1 ) ( 2 n − i + 1 ) = 1 + 2 n + 2 ∗ 3 n / 2 n E(s)=\frac{1}{2^n}*\begin{matrix} \sum_{i=0}^n C(n,\ i)(2^i+1)(2^{n-i}+1)\end{matrix}=1+2^n+2*3^n/2^n E(s)=2n1∗∑i=0nC(n, i)(2i+1)(2n−i+1)=1+2n+2∗3n/2n
代码:
#include <bits/stdc++.h>
#define sc scanf
#define pf printf
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 2e5 + 10, M = 2e4 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const int mod = 998244353;
LL n;
LL qmi(LL a, LL b)
{
LL ans = 1;
for( ; b; b >>= 1){
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
int main()
{
int t; sc("%d", &t);
while(t--) {
sc("%lld", &n);
LL ans = 1 + qmi(2, n) + 2 * qmi(3, n) * qmi(qmi(2, n), mod - 2) % mod;
pf("%lld\n", ans % mod);
}
return 0;
}