Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b6e7f66 + 6bc0999 commit 347aa8cCopy full SHA for 347aa8c
c/0837-new-21-game.c
@@ -0,0 +1,27 @@
1
+double new21Game(int n, int k, int maxPts) {
2
+ if (k == 0 || n >= k + maxPts) {
3
+ return 1.0;
4
+ }
5
+
6
+ double windowSum = 1.0;
7
+ double probability = 0.0;
8
9
+ double dp[n + 1];
10
+ dp[0] = 1.0;
11
12
+ for (int i = 1; i <= n; i++) {
13
+ dp[i] = windowSum / maxPts;
14
15
+ if (i < k) {
16
+ windowSum += dp[i];
17
+ } else {
18
+ probability += dp[i];
19
20
21
+ if (i >= maxPts) {
22
+ windowSum -= dp[i - maxPts];
23
24
25
26
+ return probability;
27
+}
0 commit comments