We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b6e7f66 commit 6bc0999Copy full SHA for 6bc0999
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