UVA 12828 & CSU 1513 DFS

UVA 12828 & CSU 1513

题目链接:

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=59187

题意:

A队五个球员,B队五个球员,各有进球概率。

有规则如果队(假设A队)肯定赢了,则不用继续继续进行比赛。

问某种比分概率。

思路:

dfs爆搜,只是有坑。

提醒:有顺序哦。

源码:

#include <iostream>

#include <cstdio>

#include <cstring>

#include <string>

#include <algorithm>

#include <cmath>

#include <vector>

#include <set>

#include <map>

#include <stack>

#include <queue>

using namespace std;

const int MAXN = 10;

double ans;

double p1[MAXN], p2[MAXN];

int lv1, lv2;

void dfs(int now1, int now2, int x ,int y, double p)

{

//    printf("now = %d, x = %d, y = %d, p = %f\n", now, x, y, p);

//    system("pause");

    if(!p)  return;

    if(x > lv1 || y > lv2)

        return;

//    if(x == y && x == 5)

//        printf("now = %d, x = %d, p = %f\n", now, x, p);

    if(x > 6 - now2 + y || y > 6 - now1 + x || now2 == 6){

        if(x == lv1 && y == lv2){

//            printf("p = %f\n", p);

            ans += p;

        }

        return;

    }

    if(now1 > now2){

        dfs(now1, now2 + 1, x, y, p * (1 - p2[now2]));

        dfs(now1, now2 + 1, x, y + 1, p * p2[now2]);

    }

    else{

        dfs(now1 + 1, now2, x, y, p * (1 - p1[now2]));

        dfs(now1 + 1, now2, x + 1, y, p * p1[now2]);

    }

}

int main (){

    int cas = 0;

    while(scanf("%lf", &p1[1]) != EOF){

        for(int i = 2 ; i <= 5 ; i++)

            scanf("%lf", &p1[i]);

        for(int i = 1 ; i <= 5 ; i++)

            scanf("%lf", &p2[i]);

        scanf("%d-%d", &lv1, &lv2);

        ans = 0;

        dfs(1, 1, 0, 0, 1.0);

        ans = ans * 100.0;

        printf("Case %d: %.2f%\n", ++cas, ans);

    }

    return 0;

}

 

你可能感兴趣的:(UVA 12828 & CSU 1513 DFS)