There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. In the i-th turn, you need to put the i-th ball to the deque. Each ball will be put to both ends of the deque with equal probability. Let the sequence…
题目大意:n个数,每个数的大小都在1~n之间.操作n次,第 i 次将第 i 个数放到一个双端队列里面,放到队列两端的概率是相等的.问操作n次之后双端队列中元素满足xi>xi+1的对数的期望,输出的数据为:(期望*2^n)%mod. 题目分析:定义状态dp(i)表示操作 i 次之后的相应期望值.则状态转移方程为: dp(i)=1/2*(dp(i-1)+k1)+1/2*(dp(i-1)+k2) (两种情况,放在队首和队尾) 其中,k1表示比a(i)小的元素可能与a(i)相邻的总次数,k2表示比a(…
题目链接: A. Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labele…
题目链接: POJ:id=3132">http://poj.org/problem?id=3132 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2822 Description A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two…