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;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值