编程介的小学生 2017-10-21 17:11 采纳率: 20.5%
浏览 994
已采纳

Map Generator

Description

The scene of the new computer game “Battles in Space: Unification” (BSU) is laid in far future. Mankind is scattered on N planets hostile to each other. A player of the game is a leader of one the planets. Using diplomatic tricks and military the player needs to occupy the rest of the planets and, doing so, reunite mankind.

Special hyperspace tunnels are used to travel from one planet to another. Each tunnel connects two of the planets and can be used for communication in both directions. Two planets can not be connected by more then one tunnel. The set of all tunnels connecting the planets is called the map of the game.

Currently, developers of BSU are working on generator of maps of the game. It has been decided to use the special algorithm called «Fine Artificial Model of Intelligence» (FAMI) for this purpose. The algorithm operates in the following way. For each pair of planets i and j (1 ≤ i < j ≤ N) a random real number Xij (0 ≤ Xij ≤ 1) is generated. Uniform distribution is used to generate random numbers and numbers Xij are generated independently. Next, if Xij ≤ P, where parameter P is a real number, then the hyperspace tunnel connecting planets i and j is added into the map being generated.

Developers wish the map generator produced connected maps. A map is said to be connected when between any pair of planets there is a path, consisting of one or more hyperspace tunnels. Unfortunately, it appears that maps generated by FAMI algorithm sometimes are not connected. You are assigned to research this phenomenon.

You need to write a program which being given numbers N and P calculates probability of generating connected map by FAMI algorithm.

Input

The input consists of two lines. The first line contains an integer number N (1 ≤ N ≤ 20), while the second line contains a real number P (0 ≤ P ≤ 1).

Output

The output needs to contain an answer – the single real number which is the probability of generating connected map by FAMI algorithm. Absolute error of the answer must not exceed 10−2.

Sample Input

3
0.5
Sample Output

0.5
Source

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-04 13:14
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?