codeforces 312 B. Archer

http://codeforces.com/problemset/problem/312/B

题意:两个人比赛射箭,先射的人射中的概率是a/b,后射的人射中的概率是c/d,问先射的人赢的概率。 思路:应该叫条件概率。。。? 不过我们可以用古典概型的思维想。每射一次看成一个点,射中的点用白色表示,没有射中的用黑色表示。如果两个人第i次都没有射中,那么就要继续第i+1 轮,而第i+1轮和之前的每一轮是独立的。等于重复这个过程。所以古典概型的样本总量应该减去宝石两个人都没有射中的点的个数,为bd-(b-a)(d-c),整理为bc+ad-a*c,设为n.要想第一个人赢,那么对于某一次,只要不是第一个人没射中,第二个人射中这种情况,就都是第一个人赢。而第一个人没射中的事件数为b-a,第二个人射中的事件数为c,总数为(b-a)*c,所以答案为(n-(b-a)*c)/n

/* ***********************************************
Author :111qqz
Created Time :2016年02月02日 星期二 15时57分06秒
File Name :code/cf/518D.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N=2E3+7;
int n,t;
double p;
double dp[N][N];
int main()
{
	#ifndef  ONLINE_JUDGE 
	freopen("code/in.txt","r",stdin);
  #endif
	ms(dp,0);
	dp[0][0] = 1;
	cin>>n>>p>>t;
	for ( int i = 0 ; i <= t ; i++)
	{
	    for ( int j = 0 ; j <= n ; j++)
	    {
		if (j==n)
		{
		    dp[i+1][j]+=dp[i][j];
		}
		else
		{
		    dp[i+1][j+1]+=dp[i][j]*p;
		    dp[i+1][j]+=dp[i][j]*(1-p);
		}
	    }
	}
	double ans = 0 ;
	for ( int j = 1 ; j <= n ; j++)
	    ans +=j*dp[t][j];
	
	printf("%.12f\n",ans);

  #ifndef ONLINE_JUDGE  
  fclose(stdin);
  #endif
    return 0;
}