题目链接:点击打开链接
题目大意:略
解题思路
相关企业
- 字节跳动
AC 代码
- Java
classSolution { publicdouble[] dicesProbability(intn) { double[] dp=newdouble[6]; Arrays.fill(dp, 1.0/6.0); for (inti=2; i<=n; i++) { double[] tmp=newdouble[5*i+1]; for (intj=0; j<dp.length; j++) { for (intk=0; k<6; k++) { tmp[j+k] +=dp[j] /6.0; } } dp=tmp; } returndp; } }
- C++
classSolution { public: vector<double>dicesProbability(intn) { vector<double>dp(6, 1.0/6.0); for (inti=2; i<=n; i++) { vector<double>tmp(5*i+1, 0); for (intj=0; j<dp.size(); j++) { for (intk=0; k<6; k++) { tmp[j+k] +=dp[j] /6.0; } } dp=tmp; } returndp; } };