forked from LuYanFCP/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path837.cpp
More file actions
27 lines (25 loc) · 716 Bytes
/
837.cpp
File metadata and controls
27 lines (25 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <algorithm>
using namespace std;
class Solution {
public:
double new21Game(int N, int K, int W) {
// vector<double> dp(K+W+1, 0.0);
double dp[20000+1];
fill(dp, dp+20000+1, 0.0);
double _sum = N-K+1;
for (int i = K; i <= N ; ++i) {
dp[i] = 1.0;
// _sum += 1.0;
}
for (int i = K-1; i >= 0; --i) {
// 问题出在这
// for (int j = i+1; j <= i+W; ++j) {
// _sum += dp[j];
// }
dp[i] = _sum * 1/W;
// printf("%d-%f--dp[i]=%f\n", i+W, dp[i+W-1], _sum);
_sum = _sum - dp[i+W] + dp[i];
}
return dp[0];
}
};