CF EDU 98 D - Radio Towers

D - Radio Towers

DP

  1. 一个塔可以覆盖以自身为中心的 1,3,5,..., 个塔
  2. 所以可以设 \(f[n]\) 为把 n 拆成奇数和的方案数,答案为 \(\frac {f[n]}{2^n}\)
  3. \(f[n]=f[n-1]+f[n-3]+f[n-5]+...+f[0/1]\)\(f[0]=1\)
  4. 可用前缀和来加速转移

神奇的是 \(f[n]\) 就是斐波那契数列

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const int mod = 998244353;
int n;
ll f[N], s[N][2];
ll qmi(ll a, ll b)
{
	ll ans = 1;
	while(b)
	{
		if (b & 1)
			ans = ans * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return ans % mod;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	f[0] = 1;
	s[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		f[i] = s[i-1][i-1&1];
		s[i][i&1] = (s[i-2][i&1] + f[i]) % mod;
	}
	
	ll up = f[n], down = qmi(2, n);
	cout << up * qmi(down, mod - 2) % mod << endl;
	return 0;
}

posted @ 2022-05-28 21:44  hzy0227  阅读(18)  评论(0编辑  收藏  举报