标签:ring template scan 多项式 type end space ons ble
听说这是一道论文题orz
\(\sum_{k = 1}^{\infty} k(p^{k} - p^{k - 1})\)
答案是这个多项式的第\(2^N - 1\)项的系数
我们反演一下,卷积变点积
\(\hat{f_{S}} = \sum_{k = 1}^{\infty} k(\hat{p_{S}}^{k} - \hat{p_{S}}^{k - 1})\)
这是个等比数列啊,怎么推呢= =
设答案为\(S\)
\(S = \infty \hat_{p}^{\infty} - \sum_{k = 0}^{\infty} \hat_{p}^{k}\)
\(\hat{p}S = \infty \hat{p}^{\infty} - \sum_{k = 1}^{\infty} \hat{p}^{k}\)
\((1 - \hat{p})S = -1\)
\(S = - \frac{1}{1 - \hat{p}}\)
所以就有
\(\hat{f} = \left\{\begin{matrix} -\frac{1}{1 - \hat{p}} & \hat{p} < 1\\ 0 & \hat{p} = 1 \end{matrix}\right.\)
最后把F反演回去就行
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
//#define ivorysi
#define MAXN 2000005
#define eps 1e-8
#define mo 974711
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
const int64 MOD = 998244353;
int N,L;
db P[MAXN],F[MAXN];
bool dcmp(db a,db b) {
return fabs(a - b) < eps;
}
template <class T>
void FMT(T *a,T ty) {
for(int i = 1 ; i < L ; i <<= 1) {
for(int j = 0 ; j < L ; ++j) {
if(j & i) {
a[j] = a[j] + ty * a[j ^ i];
}
}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
scanf("%d",&N);
L = 1 << N;
for(int i = 0 ; i < L ; ++i) scanf("%lf",&P[i]);
FMT(P,1.0);
for(int i = 0 ; i < L ; ++i) {
if(dcmp(1.0,P[i])) F[i] = 0;
else F[i] = -1/(1 - P[i]);
}
FMT(F,-1.0);
if(dcmp(F[L - 1],0)) puts("INF");
else printf("%.6lf\n",F[L - 1]);
return 0;
}
标签:ring template scan 多项式 type end space ons ble
原文地址:https://www.cnblogs.com/ivorysi/p/9055964.html