C++实现代码:
class Solution {
public:
vector<int> numberOfDice(int n) {
vector<vector<int>> dp(n + 1, vector<int>(6 * n + 1, 0));
dp[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = i; j <= 6 * i; j++){
for(int k = 1; k <= min(j, 6); k++){
dp[i][j] += dp[i-1][j-k];
}
}
}
vector<int> ans(dp[n].begin() + n, dp[n].end());
return ans;
}
};