leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0799.cpp (582B)


      1 class Solution {
      2   public:
      3     double champagneTower(int poured, int query_row, int query_glass) {
      4         static double dp[102][102];
      5         memset(dp, 0x00, sizeof(dp));
      6 
      7         dp[0][0] = (double)poured;
      8         for (int i = 0; i <= query_row; i++) {
      9             for (int j = 0; j <= i; j++) {
     10                 double split = (dp[i][j] - 1.0) / 2.0;
     11                 if (split > 0) {
     12                     dp[i + 1][j] += split;
     13                     dp[i + 1][j + 1] += split;
     14                 }
     15             }
     16         }
     17 
     18         return min(1.0, dp[query_row][query_glass]);
     19     }
     20 };