4569: Dexterina’s Lab

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:5 通过:2

题目描述

D. Dexterina’s Lab
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Dexterina and Womandark have been arch-rivals since they’ve known each other. Since both are super-intelligent teenage girls, they’ve always been trying to solve their disputes in a peaceful and nonviolent way. After god knows how many different challenges they’ve given to one another, their score is equal and they’re both desperately trying to best the other in various games of wits. This time, Dexterina challenged Womandark to a game of Nim.
Nim is a two-player game in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects from a single heap. The player who can't make a turn loses. By their agreement, the sizes of piles are selected randomly from the range [0,x]. Each pile's size is taken independently from the same probability distribution that is known before the start of the game.
Womandark is coming up with a brand new and evil idea on how to thwart Dexterina’s plans, so she hasn’t got much spare time. She, however, offered you some tips on looking fabulous in exchange for helping her win in Nim. Your task is to tell her what is the probability that the first player to play wins, given the rules as above.
Input
The first line of the input contains two integers n (1≤n≤109) and x (1≤x≤100)− the number of heaps and the maximum number of objects in a heap, respectively. The second line contains x+1 real numbers, given with up to 6 decimal places each: P(0),P(1),... ,P(X). Here, P(i) is the probability of a heap having exactly i objects in start of a game. It's guaranteed that the sum of all P(i) is equal to 1.
Output
Output a single real number, the probability that the first player wins. The answer will be judged as correct if it differs from the correct answer by at most 10-6.
Example
Input
2 2
0.500000 0.250000 0.250000
Output
0.62500000
Dexterina和Womandark自从认识以来就一直是劲敌。由于两人都是超级聪明的十几岁女孩,他们一直试图以和平和非暴力的方式解决争端。在上帝知道他们给了彼此多少不同的挑战之后,他们的分数是相等的,他们都在拼命地在各种智力游戏中击败对方。这一次,Dexterina挑战Womandark玩尼姆游戏。

尼姆是一款双人游戏,玩家轮流从不同的堆中移除物体。在每个回合中,玩家必须移除至少一个对象,并且可以从单个堆中移除任意数量的对象。不能转弯的选手会输。根据他们的协议,桩的尺寸从范围[0,x]中随机选择。每个桩的大小独立于游戏开始前已知的相同概率分布。

Womandark想出了一个全新的邪恶想法来阻止Dexterina的计划,所以她没有太多空闲时间。然而,她为你提供了一些看起来很棒的技巧,以换取帮助她在尼姆获胜。你的任务是告诉她,根据上述规则,第一个上场的球员获胜的概率是多少。


输入格式

输入的第一行包含两个整数n(1≤n≤109)和x(1≤x≤100),分别是堆的数量和堆中对象的最大数量。第二行包含x+1个实数,每个实数最多有6个小数位:P(0),P(1),P(X)。这里,P(i)是一个堆在游戏开始时正好有i个对象的概率。保证所有P(i)的和等于1。

输出格式

输出单个实数,即第一个玩家获胜的概率。如果答案与正确答案相差最多10-6,则将被判定为正确。

输入样例 复制

2 2
0.500000 0.250000 0.250000

输出样例 复制

0.62500000