标签:动态规划 ems etc class 等于 题型 http sum public
class Solution { public: vector<double> twoSum(int n) { int dp[15][70]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= 6; i ++) { dp[1][i] = 1; } for (int i = 2; i <= n; i ++) { for (int j = i; j <= 6*i; j ++) { for (int cur = 1; cur <= 6; cur ++) { if (j - cur <= 0) { break; } dp[i][j] += dp[i-1][j-cur]; } } } int all = pow(6, n); vector<double> ret; for (int i = n; i <= 6 * n; i ++) { ret.push_back(dp[n][i] * 1.0 / all); } return ret; } };
class Solution { public: vector<double> twoSum(int n) { int dp[70]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= 6; i ++) { dp[i] = 1; } for (int i = 2; i <= n; i ++) { for (int j = 6*i; j >= i; j --) { dp[j] = 0; for (int cur = 1; cur <= 6; cur ++) { if (j - cur < i-1) { break; } dp[j] += dp[j-cur]; } } } int all = pow(6, n); vector<double> ret; for (int i = n; i <= 6 * n; i ++) { ret.push_back(dp[i] * 1.0 / all); } return ret; } };
标签:动态规划 ems etc class 等于 题型 http sum public
原文地址:https://www.cnblogs.com/zhihaospace/p/12571634.html