There are n+2 towns located on a coordinate line, numbered from 0 to n+1. The i-th town is located at the point i.
You build a radio tower in each of the towns 1,2,…,n with probability 12 (these events are independent). After that, you want to set the signal power on each tower to some integer from 1 to n (signal powers are not necessarily the same, but also not necessarily different). The signal from a tower located in a town i with signal power p reaches every city c such that |c−i|<p.
After building the towers, you want to choose signal powers in such a way that:
towns 0 and n+1 don’t get any signal from the radio towers;
towns 1,2,…,n get signal from exactly one radio tower each.
For example, if n=5, and you have built the towers in towns 2, 4 and 5, you may set the signal power of the tower in town 2 to 2, and the signal power of the towers in towns 4 and 5 to 1. That way, towns 0 and n+1 don’t get the signal from any tower, towns 1, 2 and 3 get the signal from the tower in town 2, town 4 gets the signal from the tower in town 4, and town 5 gets the signal from the tower in town 5.
Calculate the probability that, after building the towers, you will have a way to set signal powers to meet all constraints.
Input
The first (and only) line of the input contains one integer n (1≤n≤2⋅105).
Output
Print one integer — the probability that there will be a way to set signal powers so that all constraints are met, taken modulo 998244353.
Formally, the probability can be expressed as an irreducible fraction xy. You have to print the value of x⋅y−1mod998244353, where y−1 is an integer such that y⋅y−1mod998244353=1.
Examples
inputCopy
2
outputCopy
748683265
inputCopy
3
outputCopy
748683265
inputCopy
5
outputCopy
842268673
inputCopy
200000
outputCopy
202370013
Note
The real answer for the first example is 14:
with probability 14, the towers are built in both towns 1 and 2, so we can set their signal powers to 1.
The real answer for the second example is 14:
with probability 18, the towers are built in towns 1, 2 and 3, so we can set their signal powers to 1;
with probability 18, only one tower in town 2 is built, and we can set its signal power to 2.
The real answer for the third example is 532. Note that even though the previous explanations used equal signal powers for all towers, it is not necessarily so. For example, if n=5 and the towers are built in towns 2, 4 and 5, you may set the signal power of the tower in town 2 to 2, and the signal power of the towers in towns 4 and 5 to 1.
题意:这里有n+2个小镇,编号为0 到 n+1,准备按照一些广播塔在编号为1到N的小镇,每个小镇被按照的概率是1/2,对于单个有一个功率p(对于每个被安装的小镇都可以是不同的),比如城市i安装了一个广播塔,则它能广播到的城市c满足|c−i|<p。在安装完成后必须满足:
- 城市0和n+1不能接收到任何广播。
- 城市1到n,每个城市恰好只能接收到一个广播站的广播。
对于任意个数的城市N,请求求出广播安装完成后,满足上述条件的概率。
思路:容易看出,对于N个城市,总共的安装方案数是2^N,所以我们需要求出满足方案的个数,设dp[i]为城市数为i时满足的方案数,因为对于当前城市i(i>=2)时
- 该城市安装广播塔(因为p是可以自己设定的),所以此时方案数为dp[i-1]
- 该城市不安装广播塔,被i-1广播到的方案数为dp[i-3](要保证i-2,和i都没有广播站,且刚好被i-1广播到),被i-2广播到的方案数为dp[i-5] 等等。
可得 d p [ i ] = d p [ i − 1 ] + d p [ i − 3 ] + d p [ i − 5 ] + . . . + dp[i] = dp[i-1] + dp[i-3] + dp[i-5] +...+ dp[i]=dp[i−1]+dp[i−3]+dp[i−5]+...+
换算后可得 d p [ i ] = d p [ i − 1 ] + d p [ i − 2 ] dp[i] = dp[i-1] + dp[i-2] dp[i]=dp[i−1]+dp[i−2]
其实就是斐波那契数列的规律(第一次做就是直接猜出的结论)
代码如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
const ll Mod = 998244353;
const int MAX = 2e5+10;
ll dp[MAX];
ll quick_pow(ll x,ll y){
ll res = 1;
x %= Mod;
while(y > 0){
if(y & 1){
res = res*x%Mod;
}
x = x*x % Mod;
y >>= 1;
}
return res%Mod;
}
ll solve(){
dp[1] = 1;
dp[2] = 1;
for(int i = 3;i <= N;i += 1){
dp[i] = (dp[i-1] + dp[i-2]) % Mod;
}
ll res = dp[N] * quick_pow(2,N*Mod-2*N) % Mod;
return res;
}
int main(void){
cin >> N;
cout << solve() << endl;
return 0;
}