It feels like a very long time. .
dp [o] [i] [mask], which represents what the final mask 9 Yes.
If the mask == 0, a representation of o rounds, Which current probability lowbit this state.
If the mask! = 0, o represents conducted round the final mask 9 is, from a probability of 10 1 in this state the number of successive start.
From dp [o] [i] [0] + 1 when after such operation can discard i, since these successive 1 has no use, even behind all this not also added +1.
#include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #define SZ(x) ((int)x.size()) #define ALL(x) (x).begin(), (x).end() #define fio ios::sync_with_stdio(false); cin.tie(0); using namespace std; const int N = 250 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-10; const double PI = acos(-1); template<class T, class S> inline void add(T &a, S b) {a += b; if(a >= mod) a -= mod;} template<class T, class S> inline void sub(T &a, S b) {a -= b; if(a < 0) a += mod;} template<class T, class S> inline bool chkmax(T &a, S b) {return a < b ? a = b, true : false;} template<class T, class S> inline bool chkmin(T &a, S b) {return a > b ? a = b, true : false;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int x, k, p; double dp[2][250][1 << 9]; double p1, p2; double (*f)[1 << 9] = dp[0]; double (*g)[1 << 9] = dp[1]; inline int getLow(int mask) { for(int i = 0; ; i++) if(mask >> i & 1) return i; } int main() { scanf("%d%d%d", &x, &k, &p); p1 = 1.0 * p / 100; p2 = 1 - p1; int c = 0, mask = (x & 511); if(mask) { for(int i = 9; ; i++) { if(x >> i & 1) c++; else break; } } else { c = getLow(x); } f[c][mask] = 1; for(int o = 0; o < k; o++) { swap(f, g); for(int i = 0; i <= 240; i++) for(int mask = 0; mask < (1 << 9); mask++) f[i][mask] = 0; for(int i = 0; i < 240; i++) { for(int mask = 0; mask < (1 << 9); mask++) { if(mask) { // +1 if(mask + 1 == (1 << 9)) { f[i + 9][0] += g[i][mask] * p2; } else { f[i][mask + 1] += g[i][mask] * p2; } // *2 int nmask = (mask << 1) & 511; int bit = mask >> 8 & 1; if(nmask) { if(bit) { f[i + 1][nmask] += g[i][mask] * p1; } else { f[0][nmask] += g[i][mask] * p1; } } else { f[9][0] += g[i][mask] * p1; } } else { // +1 f[0][1] += g[i][mask] * p2; // *2 f[i + 1][0] += g[i][mask] * p1; } } } } double ans = 0; for(int i = 0; i <= 240; i++) { for(int mask = 0; mask < (1 << 9); mask++) { if(mask) { ans += getLow(mask) * f[i][mask]; } else { ans += i * f[i][mask]; } } } printf("%.12f\n", ans); return 0; } /* */