Codevs 1060 Funny Games dp

Source: Internet
Author: User

1060 Comedy World Cup

Time limit:20 Sec Memory limit:256 MB

Topic Connection http://codevs.cn/problem/1060/
Description with the end of the World Cup group game, France, Argentina and other world's strong teams have been eliminated, people heartache unceasingly. So there are

People organized a funny World Cup, re-organized these eliminated teams to play with the World Cup. You and your friends

The friends gladly went to buy tickets. But the funny World Cup tickets are sold in a very special way, and they only have two tickets for the ball. Class A

Tickets------Free Ticket class B-------double price tickets. When the purchase is made by a staff member by toss, cast to the front

Buy a Class A ticket, the opposite of Buy B ticket. And because it's a market economy, organizers can't daotie money, so they're always ready

The same number of Class A and Class B tickets. You and your friends are lucky enough to be in the last two positions of a wonderful game.

At this time the staff began to sell coins. But it is even more fortunate that when the staff comes to you, he finds that there is no need

Toss the coin again, because the two tickets are all free tickets.

You and your friends in the joy, want to calculate the queue at the end of the two people at the same time the probability of getting a ticket?

(including both a-class or B-ticket) assumes that the staff has prepared 2n tickets, of which n a Class A ticket, n a Class B ticket, and the person in the queue each must and can only buy a ticket (whether the toss is to buy a or buy B).

a is completely coincident, or can be shifted up or down by a line < Span id= "mathjax-span-1329" class= "math" style= "WIDTH:0.958EM; Display:inline-block; " >a a section of the complete coincidence, it means that Qiushi Big Brother blew out a part of the melody of her sister. Input file only one row, including the number of tickets 2n. where, 0<n<=1250, n is an integer. Output

The output file contains only one number, the probability of getting the same ticket, exactly 4 digits after the decimal point.

Sample Input the
Sample Output
0.9500
HINT

Test Instructions

Exercises

DP[I][J] indicates the probability that the first I person took J-ticket a

Transfer equation

     for(intI=1; i<=n;i++) {dp[i][0]=dp[i-1][0]*0.5;  for(intj=1; j<=n/2; j + +)        {            if(j==n/2) Dp[i][j]=dp[i-1][j-1]*0.5+dp[i-1][j]; ElseDp[i][j]=dp[i-1][j-1]*0.5+dp[i-1][j]*0.5; }    }

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200001#defineMoD 10007#defineEPS 1e-9intNum;Charch[ -];//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=0x3f3f3f3f;/*inline void P (int x) {num=0;if (!x) {Putchar (' 0 ');p UTS (""); return;}    while (x>0) ch[++num]=x%10,x/=10;    while (Num) Putchar (ch[num--]+48); Puts ("");}*/inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;} InlinevoidPintx) {Num=0;if(!x) {Putchar ('0');p UTS ("");return;}  while(x>0) ch[++num]=x%Ten, x/=Ten;  while(Num) Putchar (ch[num--]+ -); Puts ("");}//**************************************************************************************Doubledp[ the][ the];intMain () {intn=read (); dp[0][0]=1;  for(intI=1; i<=n;i++) {dp[i][0]=dp[i-1][0]*0.5;  for(intj=1; j<=n/2; j + +)        {            if(j==n/2) Dp[i][j]=dp[i-1][j-1]*0.5+dp[i-1][j]; ElseDp[i][j]=dp[i-1][j-1]*0.5+dp[i-1][j]*0.5; }} printf ("%.4lf\n", dp[n-2][n/2]*2);}

Codevs 1060 Funny Games dp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.