Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- double soupServings(int N) {
- if(N > 4275) return 1.0;
- int size = (N+24)/25;
- vector<vector<double>> dp(size+1, vector<double>(size+1, 0));
- dp[size][size] = 1;
- for(int i = size; i >= 1; --i) {
- for(int j = size; j >= 1; --j) {
- if(i != 0) dp[max(0, i-4)][j] += 0.25*dp[i][j];
- if(i != 0 && j != 0) {
- dp[max(0, i-3)][max(0, j-1)] += 0.25*dp[i][j];
- dp[max(0, i-2)][max(0, j-2)] += 0.25*dp[i][j];
- dp[max(0, i-1)][max(0, j-3)] += 0.25*dp[i][j];
- }
- }
- }
- double p = 0.5*dp[0][0];
- for(int j = 1; j <= size; ++j) p += dp[0][j];
- return p;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement