Algorithm
Problem Statement for TestBettingStrategy Problem link- https://community.topcoder.com/stat?c=problem_statement&pm=7422&rd=10663 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
double dp[1001][51][51];
class TestBettingStrategy {
double rec(int sum, int rem, int cur, int &gol, double prb) {
if(sum >= gol)
return 1;
if(sum <= 0 || rem <= 0 || pow(2, cur) > sum)
return 0;
double &ret = dp[sum][rem][cur];
if(ret == ret)
return ret;
ret = 0;
return ret = prb * rec(sum + pow(2, cur), rem - 1, 0, gol, prb) +
(1.0 - prb) * rec(sum - pow(2, cur), rem - 1, cur + 1, gol, prb);
}
public:
double winProbability(int initSum, int goalSum, int rounds, int prob) {
memset(dp, -1, sizeof dp);
return rec(initSum, rounds, 0, goalSum, 1.0 * prob / 100.0);
}
};
Copy The Code &
Try With Live Editor
Input
11
4
50
Output
Demonstration
TopCoder Solution SRM339-D1-500 Statement for TestBettingStrategy C,C++, Java, Js and Python ,SRM339-D1-500,TopCoder Solution