当前位置:网站首页>[sword finger offer] 60 Points of N dice
[sword finger offer] 60 Points of N dice
2022-07-06 18:18:00 【LuZhouShiLi】
The finger of the sword Offer 60. n The number of dice
subject
hold n A dice on the ground , The sum of the points on the up side of all dice is s. Input n, Print out s The probability that all possible values of the . You need to return the answer with an array of floating-point numbers , Among them the first i The elements represent this n The number of points that a die can roll i The probability of the smaller one .
Ideas
- First, use the first dimension of the array to represent the stage , That is, throw a few dice
- Then use the second dimension representation of the array to roll these dice , Possible points
- The value of the array represents , The number of points in this stage
Code
class Solution {
public:
vector<double> dicesProbability(int n) {
int dp[12][70];
memset(dp,0,sizeof(dp));// All initialization 0
for(int i = 1; i <= 6; i++)
{
dp[1][i] = 1;// Status array initialization
}
for(int i = 2; i <= n; i++)
{
// The maximum number of points It must be 6 * i
for(int j = i; j <= 6 * i; j++)
{
for(int cur = 1; cur <= 6; cur++)
{
if(j - cur <= 0)
{
break;
}
// But look No i A dice , Points may be 1 2 3 4 5 6 So points j The number of occurrences is determined by the end of the throw i - 1 A dice Corresponding points j - 1 j - 2 j - 6 The sum of the number of occurrences is transformed
dp[i][j] += dp[i - 1][j - cur];
}
}
}
int all = pow(6,n);// All possibilities
vector<double> ret;
for(int i = n; i <= n * 6; i++)
{
ret.push_back(dp[n][i] * 1.0 / all);
}
return ret;
}
};
边栏推荐
- Introduction to the usage of model view delegate principal-agent mechanism in QT
- Olivetin can safely run shell commands on Web pages (Part 1)
- Cobra 快速入门 - 专为命令行程序而生
- Why does wechat use SQLite to save chat records?
- 容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
- Jerry's access to additional information on the dial [article]
- [.Net core] solution to error reporting due to too long request length
- Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
- 2022暑期项目实训(二)
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
猜你喜欢

队列的实现

MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...

Maixll-Dock 摄像头使用

Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022

Interesting - questions about undefined

【Swoole系列2.1】先把Swoole跑起来

Virtual machine VirtualBox and vagrant installation
![Jerry's updated equipment resource document [chapter]](/img/6c/17bd69b34c7b1bae32604977f6bc48.jpg)
Jerry's updated equipment resource document [chapter]

Distill knowledge from the interaction model! China University of science and Technology & meituan proposed virt, which combines the efficiency of the two tower model and the performance of the intera

30 minutes to understand PCA principal component analysis
随机推荐
趣-关于undefined的问题
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
微信为什么使用 SQLite 保存聊天记录?
DNS hijacking
Why does wechat use SQLite to save chat records?
Kill -9 system call used by PID to kill process
celery最佳实践
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
Declval of template in generic programming
传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
TOP命令详解
Excellent open source fonts for programmers
【剑指 Offer】 60. n个骰子的点数
Reprint: defect detection technology of industrial components based on deep learning
30 minutes to understand PCA principal component analysis
ASEMI整流桥DB207的导通时间与参数选择
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
C语言自动预订飞机票问题
Jerry's access to additional information on the dial [article]
Introduction to the usage of model view delegate principal-agent mechanism in QT