codevs 1060 搞笑运动会 dp

时间:2024-10-06 11:34:20

1060 搞笑世界杯

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codevs.cn/problem/1060/

Description

  随着世界杯小组赛的结束,法国,阿根廷等世界强队都纷纷被淘汰,让人心痛不已. 于是有

人组织了一场搞笑世界杯,将这些被淘汰的强队重新组织起来和世界杯一同比赛.你和你的朋

友欣然去购买球票.不过搞笑世界杯的球票出售方式也很特别,它们只准备了两种球票.A 类

票------免费球票 B 类票-------双倍价钱球票.购买时由工作人员通过掷硬币决定,投到正面

的买A类票, 反面的买B类票.并且由于是市场经济,主办方不可能倒贴钱,所以他们总是准备

了同样多的A类票和B类票.你和你的朋友十分幸运的排到了某场精彩比赛的最后两个位置.

这时工作人员开始通过硬币售票.不过更为幸运的是当工作人员到你们面前时他发现已无需

再掷硬币了,因为剩下的这两张票全是免费票。

你和你的朋友在欣喜之余,想计算一下排在队尾的两个人同时拿到一种票的概率是多少

(包括同时拿A 类票或B类票) 假设工作人员准备了2n 张球票,其中n 张A类票,n 张B类票,并且排在队伍中的人每人必须且只能买一张球票(不管掷到的是该买A 还是该买B).

A的某一段完全重合,或者能够经过上下左右平移与折线A的某一段完全重合,则表示秋实大哥吹出了妹子的一部分旋律。

Input

输入文件仅一行,包含球票数2n . 其中,0<n<=1250 ,n 为整数。

Output

输出文件只包含一个数,为拿到同一种票的概率,精确到小数点后4 位。

Sample Input

256

Sample Output

0. 9500

HINT

题意

题解:

dp[i][j]表示前i个人拿了j张A票的概率

转移方程

    for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]*0.5;
for(int j=;j<=n/;j++)
{
if(j==n/)
dp[i][j]=dp[i-][j-]*0.5+dp[i-][j];
else
dp[i][j]=dp[i-][j-]*0.5+dp[i-][j]*0.5;
}
}

代码:

//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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** double dp[][];
int main()
{
int n=read();
dp[][]=;
for(int i=;i<=n;i++)
{
dp[i][]=dp[i-][]*0.5;
for(int j=;j<=n/;j++)
{
if(j==n/)
dp[i][j]=dp[i-][j-]*0.5+dp[i-][j];
else
dp[i][j]=dp[i-][j-]*0.5+dp[i-][j]*0.5;
}
}
printf("%.4lf\n",dp[n-][n/]*);
}