Fxtz II

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/others) total submission (s): 498 accepted submission (s): 266

Problem descriptioncirno is playing a fighting game called "fxtz" with sanae.

Sanae is a chushou (master) of the game while cirno is a shabao (noob ). since cirno is a shabao, she just presses a random key on the keyboard for every 0.5 second, expecting to make a bishaji.

The battle begins. Having tried exactly 9 times, she finally makes a bishaji! She find herself summoned n icebils !!! Then sanae's HP decreases to 0 immediately .... it shoshould have been like that. but cirno is too simple, always navie. she doesn't know how to handle the icebils, So she starts to press the keyboard at random, again.

Let's see how the iceball damages. each iceball has a fixed energy: the first ball's energy is 2 ^ 0, the second ball's energy is 2 ^ 1 ,..., and the n-th ball's energy is 2 ^ (N-1 ). the damage caused by an iceball is equal to its energy. cirno will shoot N times. since cirno is pressing the keyboard at random, each time cirno will choose exactly one iceball with equal possibility to shoot out. once shot out, the iceball can't be chosen again. and even worse, the target may be either her opponent or herself, with equal possibility (50% ). what a big shabao she is. ===

During shooting, once cirno's HP is less than sanae's, she will lose the game. Otherwise, she wins.

You may assume sanae did nothing while cirno's shooting (all damages are caused by cirno's iceball ), and their original HP are both 2 ^ N (no one will die in the middle of the battle unless cirno's HP is less than sanae's ).

Here comes the question: Can you calculate the possibility of cirno's victory?

Inputthe first line an integer c (C <= 30), the number of test cases.

For each case, the only line contains one integer N (0 <n <= 500), indicating the number of icebils.

Outputfor each case output a fraction, the possibility of cirno's vicement. The fraction must be supported CED.

Sample Input

214

Sample output

1/235/128

Sourcethe 36th ACM/ICPC Asia Regional Beijing site -- online contest

Recommendlcy | we have carefully selected several similar problems for you: 4049 4050 4044 4047

Question:

There are n energy balls with 2 ^ 0, 2 ^ 1, 2 ^ 2,... 2 ^ n-1

This person chooses an energy ball at random each time with the same probability. After the selection, the person can be deemed to have disappeared and cannot be selected again. The probability of hitting himself or the enemy is 50%,

In the process, if your blood volume is smaller than the other party, you can lose the game and ask yourself the probability of winning.

Solution:

This is an analytical probability question.

First, get the question and see that the output style is dividing the numerator by the denominator. in this format, we cannot just calculate the probability. We need to calculate the number of methods.

(1) it can be determined that the denominator is simplified, that is, the total number of methods. It should be after N snowballs are fully arranged, and then decide who each snowball hits.

That is, n! * 2 ^ n

(2) analyze the numerator, that is, the number of winning methods.

Now N snowballs are arranged in a row,

It is certain that the nth snowball hits the other party; otherwise, I will lose.

Because the energy of the nth Snowball is 2 ^ (n-1) greater than the total energy of the remaining n-1 balls

So we will discuss the number of winning methods based on the position of the nth ball. If this ball is marked as X, the other balls are marked *

1. the nth Snowball is in the 1th position

*****************

N-1 snowballs only need to be randomly arranged (n-1 )!, And anyone who can play 2 ^ (n-1), so the number of methods is: C [n-1] [0] * (n-1 )! * 2 ^ (n-1)

2. the nth Snowball is in the 2nd position.

* X ****************

Just select 1 snowball on the left, N-2 Snowball can be casually, so the number of methods is: C [n-1] [1] * (n-2 )! * 2 ^ (n-2)

3. the nth Snowball is in the third position.

* X ***************

You only need to select 2 snowballs on the left, and meet the requirements that DP [2], n-3 snowballs can casually, DP [2] * C [n-1] [2] * (n-3 )! * 2 ^ (n-3)

Note: DP [N] records the number of methods that meet the requirements when n snowballs exist.

4. the nth Snowball is in the I position

**********

Just select the I-1 snowballs on the left and meet the requirement that is DP [I-1], the rest of the n-I balls casually put (n-I )! * 2 ^ (n-I) method, so the number of methods DP [I-1] * C [n-1] [I-1] * (N-I )! * 2 ^ (n-I)

Therefore, the total number of winning Methods DP [N] = sum {DP [I-1] * C [n-1] [I-1] * (N-I )! * 2 ^ (n-I)} 1 <= I <= N

Reduction: DP [N] = sum {DP [I-1] * (n-1 )! * 2 ^ (n-I)/(I-1 )! } 1 <= I <= N

That is, DP [N] = (n-1 )! * (DP [0] * 2 ^ (n-1)/0! + Dp [1] * 2 ^ (n-2)/1! + Dp [2] * 2 ^ (n-3)/2! +... + Dp [N-2] * 2 ^ 1/(n-2 )! + Dp [n-1] * 2 ^ 0/(n-1 )! )

While DP [n-1] = (n-2 )! * (DP [0] * 2 ^ (n-2)/0! + Dp [1] * 2 ^ (n-3)/1! + Dp [2] * 2 ^ (n-4)/2! +... + Dp [N-2] * 2 ^ 0/(n-2 )! )

So we can see that DP [N] = (n-1) * 2 * DP [n-1] + dp [n-1]

So DP [N] = (2 * N-1) * DP [n-1], DP [0] = 1,

So the number of winning methods is: 1*3*5*7 *... * (2 * N-1)

In summary (1), (2), the answer is 1*3*5*7 *... * (2 * N-1)/(n! * 2 ^ N)

Solution code:

import java.util.*;import java.math.*;public class Main{public static void main(String[] args){Scanner scan=new Scanner(System.in);int T=scan.nextInt();while(T-- >0){int n=scan.nextInt();BigInteger sum=new BigInteger("1"),x=new BigInteger("1");for(int i=1;i<=n;i++){sum=sum.multiply(BigInteger.valueOf(2*i));x=x.multiply(BigInteger.valueOf(2*i-1));}BigInteger gcd0=x.gcd(sum);System.out.println(x.divide(gcd0)+"/"+sum.divide(gcd0));}scan.close();}}

HDU 4043 fxtz II (combined mathematics-permutation and combination)