当前位置:网站首页>[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;
}
};
边栏推荐
- 编译原理——自上而下分析与递归下降分析构造(笔记)
- Alibaba cloud international ECS cannot log in to the pagoda panel console
- Interesting - questions about undefined
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
- Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
- Codeforces Round #803 (Div. 2)
- Why does wechat use SQLite to save chat records?
- 最新财报发布+天猫618双榜第一,耐克蓄力领跑下个50年
- Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
猜你喜欢

Rb157-asemi rectifier bridge RB157

【.NET CORE】 请求长度过长报错解决方案

std::true_ Type and std:: false_ type

Prophet模型的简介以及案例分析

队列的实现

Maixll-Dock 摄像头使用

78 year old professor Huake has been chasing dreams for 40 years, and the domestic database reaches dreams to sprint for IPO

1700C - Helping the Nature

从交互模型中蒸馏知识!中科大&美团提出VIRT,兼具双塔模型的效率和交互模型的性能,在文本匹配上实现性能和效率的平衡!...

Compilation Principle -- C language implementation of prediction table
随机推荐
微信小程序中给event对象传递数据
Excellent open source fonts for programmers
Jerry is the custom background specified by the currently used dial enable [chapter]
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
Grafana 9.0 is officially released! It's the strongest!
面试突击62:group by 有哪些注意事项?
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
[swoole series 2.1] run the swoole first
Principle and usage of extern
node の SQLite
Declval of template in generic programming
2022 Summer Project Training (I)
J'aimerais dire quelques mots de plus sur ce problème de communication...
Redis的五种数据结构
华为0基金会——图片整理
测试123
Markdown grammar - better blogging
带你穿越古罗马,元宇宙巴士来啦 #Invisible Cities
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
Excel usage record