bzoj4036 [HAOI2015] bitwise OR

Posted by Magneto on Sun, 26 Apr 2020 16:45:59 +0200

Title Link

solution

Use \ (f[i][j] \) to indicate the probability of \ (j \) after the \ (I \) operation.

Then there are \ (f [i] [J] = \ sum \ limits {s | s | 2 = J} f [I - 1] [s | 1] \ times P [s | 2] \)

So the probability that the number is \ (i \) after the \ (K \) operation is \ (P ^ k \ U i \). The multiplication here is set convolution.

There is still no egg use. We use \ (FWT \) to convert it to a point value.

Then the probability of \ (I \) after the first \ (K \) operation is \ (p_i'^k \). The multiplication here is a simple number multiplication.

Then the expected number of times the array becomes \ (i \) is, the answer is \ (\ sum \ limits {t = 1} ^ {\ infty} t (P \ i ^ k-p \ U i ^ {k-1}) = - (1 + P \ U i ^ 2 + P \ u i ^ 3 + \ cdots) = \ frac {1} {X-1} \)

Then use \ (IFWT \) to convert back.

code

/*
* @Author: wxyww
* @Date:   2020-04-26 08:51:04
* @Last Modified time: 2020-04-26 09:10:07
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 1 << 21;
ll read() {
	ll x = 0,f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1; c = getchar();
	}
	while(c >= '0' && c <= '9') {
		x = x * 10 + c - '0'; c = getchar();
	}
	return x * f;
}
double a[N];
int main() {
	int n = read();
	for(int i = 0;i < (1 << n);++i)
		scanf("%lf",&a[i]);
	
	for(int i = 0;i < n;++i)
		for(int j = 0;j < (1 << n);++j)
			if(!((j >> i) & 1))
				a[j | (1 << i)] += a[j];

	for(int i = 0;i < (1 << n);++i) {
		if(a[i] - 1 >= -1e-8) {
			if(i == (1 << n) - 1) a[i] = 0;
			else {puts("INF");return 0;}		
		}
		else a[i] = 1 / (a[i] - 1);
	}
	for(int i = 0;i < n;++i) 
		for(int j = 0;j < (1 << n);++j)
			if(!((j >> i) & 1))
				a[j | (1 << i)] -= a[j];
	printf("%.10lf\n",a[(1 << n) - 1]);
	return 0;
}


/*
2
0.25 0.25 0.25 0.25

*/

Topics: C++