leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0799.cpp (582B)
0 class Solution {
1 public:
2 double champagneTower(int poured, int query_row, int query_glass) {
3 static double dp[102][102];
4 memset(dp, 0x00, sizeof(dp));
6 dp[0][0] = (double)poured;
7 for (int i = 0; i <= query_row; i++) {
8 for (int j = 0; j <= i; j++) {
9 double split = (dp[i][j] - 1.0) / 2.0;
10 if (split > 0) {
11 dp[i + 1][j] += split;
12 dp[i + 1][j + 1] += split;
13 }
14 }
15 }
17 return min(1.0, dp[query_row][query_glass]);
18 }
19 };