class Solution {
public:
vector<double> statisticsProbability(int num) {
vector<double> dp(6, 1.0 / 6.0);
for (int i = 2; i <= num; i++) {
vector<double> tmp(5 * i + 1, 0);
for (int j = 0; j < dp.size(); j++) {
for (int k = 0; k < 6; k++) {
tmp[j + k] += dp[j] / 6.0;
}
}
dp = tmp;
}
return dp;
}
};
[leetcode] n个骰子的点数
于 2024-07-01 10:58:43 首次发布