当前位置:网站首页>[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;
}
};
边栏推荐
- 传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
- Excellent open source fonts for programmers
- Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
- 關於這次通信故障,我想多說幾句…
- TOP命令详解
- DOM简要
- RB157-ASEMI整流桥RB157
- Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
- Interview shock 62: what are the precautions for group by?
- 2022 Summer Project Training (II)
猜你喜欢
Implementation of queue
Grafana 9.0 is officially released! It's the strongest!
ASEMI整流桥DB207的导通时间与参数选择
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
[Android] kotlin code writing standardization document
F200 - UAV equipped with domestic open source flight control system based on Model Design
Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
C语言通过指针交换两个数
随机推荐
STM32+ESP8266+MQTT协议连接OneNet物联网平台
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
容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
C language exchanges two numbers through pointers
队列的实现
Maixll-Dock 摄像头使用
MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
Common - magic number 7
微信小程序中给event对象传递数据
Transfer data to event object in wechat applet
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
【Android】Kotlin代码编写规范化文档
Cocos2d Lua 越来越小样本 内存游戏
Declval of template in generic programming
D binding function
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
UDP协议:因性善而简单,难免碰到“城会玩”
30 分钟看懂 PCA 主成分分析
epoll()无论涉及wait队列分析