用C++写Mr. Wor's router at home is broken again. After some repairs, he needs to reconnect the Ethernet cables to the router. It is known that Mr. Wor's router has n ports, and there are n Ethernet cables. Then, Mr. Wor will sequentially insert the i -th Ethernet cable to the i -th port, for all i from 1 to n . However, due to Mr. Wor's mysterious actions, the first m cables were not inserted into their designated ports, but were inserted into m ports uniformly at random. For the remaining cables, when cable i is being inserted, if port i is not occupied, then cable i will be inserted into port i . Otherwise, cable i will be inserted into a randomly chosen unoccupied port. Mr. Wor wants to know the probability that the last cable, cable n , is plugged into port n . Input Only one line contains two integers n,m(1≤n≤10,0≤m≤n) , denoting the number of cables and the number of cables which was inserted randomly. Output Print the probability in one line. Your answer is considered correct if the relative or absolute error is less than or equal to 10−6 .

时间: 2024-01-29 19:03:43 浏览: 35
```c++ #include <iostream> #include <cstdio> using namespace std; const int N = 15; double f[N][N]; int main() { int n, m; scanf("%d%d", &n, &m); f[1][0] = 1; f[1][1] = 0; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i-1 && j <= n-m; j++) { f[i][j] = (i-j)*f[i-1][j]/i + (j+1)*f[i-1][j+1]/i; } } printf("%.8lf", f[n][n-m]); return 0; } ```
相关问题

c++ s.assign

`std::string`类的`assign()`函数用于将一个字符串或字符数组的内容赋值给该字符串对象。具体使用方式如下: ```cpp string& assign (const string& str); string& assign (const string& str, size_t subpos, size_t sublen); string& assign (const char* s); string& assign (const char* s, size_t n); string& assign (size_t n, char c); template <class InputIterator> string& assign (InputIterator first, InputIterator last); ``` - `assign(const string& str)`:将`str`字符串的内容赋值给该字符串对象。 - `assign(const string& str, size_t subpos, size_t sublen)`:将`str`字符串从下标`subpos`开始的长度为`sublen`的子串内容赋值给该字符串对象。 - `assign(const char* s)`:将C风格的字符串`s`的内容赋值给该字符串对象。 - `assign(const char* s, size_t n)`:将C风格的字符串`s`前`n`个字符的内容赋值给该字符串对象。 - `assign(size_t n, char c)`:将`n`个字符`c`的内容赋值给该字符串对象。 - `template <class InputIterator> assign(InputIterator first, InputIterator last)`:将迭代器区间`[first, last)`范围内的内容赋值给该字符串对象。 下面是一个示例: ```cpp #include <string> #include <iostream> int main() { std::string s1("hello"); std::string s2("world"); s1.assign(s2); // 将s2的内容赋值给s1 std::cout << s1 << std::endl; // 输出:world s1.assign(s2, 2, 3); // 将s2从下标2开始,长度为3的子串赋值给s1 std::cout << s1 << std::endl; // 输出:rld s1.assign("hello"); // 将C风格字符串"hello"的内容赋值给s1 std::cout << s1 << std::endl; // 输出:hello s1.assign("world", 3); // 将C风格字符串"world"的前3个字符的内容赋值给s1 std::cout << s1 << std::endl; // 输出:wor s1.assign(5, 'a'); // 将5个字符'a'的内容赋值给s1 std::cout << s1 << std::endl; // 输出:aaaaa std::string s3("hello, world"); s1.assign(s3.begin() + 7, s3.end()); // 将s3从下标7开始到结尾的子串赋值给s1 std::cout << s1 << std::endl; // 输出:world return 0; } ``` 输出结果为: ``` world rld hello wor aaaaa world ```

判断hello wor ld.sh是否具有写权限?

可以使用`-w`选项来判断文件是否具有写权限。具体命令如下: ```bash if [ -w "hello wor ld.sh" ]; then echo "hello wor ld.sh具有写权限" else echo "hello wor ld.sh没有写权限" fi ``` 在上面的代码中,`[ -w "hello wor ld.sh" ]`表示判断文件`hello wor ld.sh`是否具有写权限。如果具有写权限,则输出“hello wor ld.sh具有写权限”,否则输出“hello wor ld.sh没有写权限”。

相关推荐

最新推荐

recommend-type

【004期】SPSS聚类分析.doc

用数据文件【004期】SPSS聚类分析.sav做实例分析。 为了研究亚洲国家或地区的经济发展和文化教育水平,以便对亚洲国家和地区进行分类研究,进行聚类分析。
recommend-type

2019年12月西安电子科技大学计算机安全导论期末题.doc

西安电子科技大学2019年12月25日计算机安全导论期末试题,可以期末复习的用来参考,试题比较灵活,建议复习时以理解为主,老师期末会划重点,他举的例子一定要理解
recommend-type

CC1100WOR功能介绍

CC1100 /CC2500 Wake-on-Radio(电磁波唤醒)功能原理 CC1100的GDO引脚可以配置为在MCU希望的条件下产生一个中断...在收到数据包后,芯片不会自动返回WOR状态,这意味着,MCU需要手动的发布WOR滤波使芯片返回WOR状态。
recommend-type

六首页数字藏品NFT交易网React NextJS网站模板 六首页数字藏品nft交易网反应NextJS网站模板

六首页数字藏品NFT交易网React NextJS网站模板 六首页数字藏品nft交易网反应NextJS网站模板
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依