542 - France '98 (概率 dp)

2024-06-01 21:48
文章标签 dp 98 概率 542 france

本文主要是介绍542 - France '98 (概率 dp),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  France '98 

Today the first round of the Soccer World Championship in France is coming to an end. 16 countries are remaining now, among which the winner is determined by the following tournament:

 1 Brazil -----++-- ? --+2 Chile ------+       |+-- ? --+3 Nigeria ----+       |       |+-- ? --+       |4 Denmark ----+               |+-- ? --+5 Holland ----+               |       |+-- ? --+       |       |6 Yugoslavia -+       |       |       |+-- ? --+       |7 Argentina --+       |               |+-- ? --+               |8 England ----+                       |+-- World Champion9 Italy ------+                       |+-- ? --+               |
10 Norway -----+       |               |+-- ? --+       |
11 France -----+       |       |       |+-- ? --+       |       |
12 Paraguay ---+               |       |+-- ? --+
13 Germany ----+               |+-- ? --+       |
14 Mexico -----+       |       |+-- ? --+
15 Romania ----+       |+-- ? --+
16 Croatia ----+

For each possible match A vs. B between these 16 nations, you are given the probability that team A wins against B. This (together with the tournament mode displayed above) is sufficient to compute the probability that a given nation wins the World Cup. For example, if Germany wins against Mexico with 80%, Romania against Croatia with 60%, Germany against Romania with 70% and Germany against Croatia with 90%, then the probability that Germany reaches the semi-finals is 80% * (70% * 60% + 90% * 40%) = 62.4%.


Your task is to write a program that computes the chances of the 16 nations to become the World Champion '98.

Input 

The input file will contain just one test case.

The first 16 lines of the input file give the names of the 16 countries, from top to bottom according to the picture given above.

Next, there will follow a 16 $\times$ 16 integer matrix P where element pij gives the probability in percent that country #i defeats country #j in a direct match. Country #i means the i-th country from top to bottom given in the list of countries. In the picture above Brazil is #1 and Germany is #13, so p1,13 = 55 would mean that in a match between Brazil and Germany, Brazil wins with a probability of 55%.

Note that matches may not end with a draw, i.e. pij + pji = 100 for all i,j.

Output 

Output 16 lines of the form ``  XXXXXXXXXX   p= Y . YY %", where  XXXXXXXXXX  is the country's name, left-justified in a field of 10 characters, and  Y . YY  is their chance in percent to win the cup, written to two decimal places. Use the same order of countries like in the input file.

Sample Input 

Brazil
Chile
Nigeria
Denmark
Holland
Yugoslavia
Argentina
England
Italy
Norway
France
Paraguay
Germany
Mexico
Romania
Croatia
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
40 55 40 50 45 40 40 55 35 45 30 45 30 45 40 40
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
35 50 35 45 40 35 35 50 30 40 25 40 25 40 35 35
55 70 55 65 60 55 55 70 50 60 45 60 45 60 55 55
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
60 75 60 70 65 60 60 75 55 65 50 65 50 65 60 60
45 60 45 55 50 45 45 60 40 50 35 50 35 50 45 45
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50
50 65 50 60 55 50 50 65 45 55 40 55 40 55 50 50

Sample Output 

Brazil     p=8.54%
Chile      p=1.60%
Nigeria    p=8.06%
Denmark    p=2.79%
Holland    p=4.51%
Yugoslavia p=7.50%
Argentina  p=8.38%
England    p=1.56%
Italy      p=9.05%
Norway     p=3.23%
France     p=13.72%
Paraguay   p=3.09%
Germany    p=13.79%
Mexico     p=3.11%
Romania    p=5.53%
Croatia    p=5.53%

题意:给定16只球队名字和i和j队比赛i队赢的概率。求每个球队得冠军概率

思路:dp[k][i]表示第i只球队在第k轮出线的概率。 那么可得方程dp[k][i] = dp[k - 1][i] * dp[k - 1][j] * (i赢j概率)。然后要多个判断,i和j要在同一组内并且i和j在上一场比赛中不是对手。

代码:

#include <stdio.h>
#include <string.h>
const int N = 20;
const int d[5] = {1, 2, 4, 8, 16};
int i, j, k;
double v[N][N], dp[N - 10][N];
char name[N][105];int main() {for (i = 1; i <= 16; i ++)gets(name[i]);for (i = 1; i <= 16; i ++)for (j = 1; j <= 16; j ++) {scanf("%lf", &v[i][j]);}for (i = 1; i <= 16; i ++)dp[0][i] = 100;for (k = 1; k <= 4; k ++) for (i = 1; i <= 16; i ++)for (j = 1; j <= 16; j ++) {if ((i - 1) / d[k] == (j - 1) / d[k] && (i - 1) / d[k - 1] != (j - 1) / d[k - 1])dp[k][i] += dp[k - 1][i] * dp[k - 1][j] * v[i][j] / 10000;}for (i = 1; i <= 16; i ++) {printf("%-10s p=%.2f%%\n", name[i], dp[4][i]);}return 0;
}


这篇关于542 - France '98 (概率 dp)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1022202

相关文章

hdu4826(三维DP)

这是一个百度之星的资格赛第四题 题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=500 题意:从左上角的点到右上角的点,每个点只能走一遍,走的方向有三个:向上,向下,向右,求最大值。 咋一看像搜索题,先暴搜,TLE,然后剪枝,还是TLE.然后我就改方法,用DP来做,这题和普通dp相比,多个个向上

hdu1011(背包树形DP)

没有完全理解这题, m个人,攻打一个map,map的入口是1,在攻打某个结点之前要先攻打其他一个结点 dp[i][j]表示m个人攻打以第i个结点为根节点的子树得到的最优解 状态转移dp[i][ j ] = max(dp[i][j], dp[i][k]+dp[t][j-k]),其中t是i结点的子节点 代码如下: #include<iostream>#include<algorithm

hdu4865(概率DP)

题意:已知前一天和今天的天气概率,某天的天气概率和叶子的潮湿程度的概率,n天叶子的湿度,求n天最有可能的天气情况。 思路:概率DP,dp[i][j]表示第i天天气为j的概率,状态转移如下:dp[i][j] = max(dp[i][j, dp[i-1][k]*table2[k][j]*table1[j][col] )  代码如下: #include <stdio.h>#include

usaco 1.1 Broken Necklace(DP)

直接上代码 接触的第一道dp ps.大概的思路就是 先从左往右用一个数组在每个点记下蓝或黑的个数 再从右到左算一遍 最后取出最大的即可 核心语句在于: 如果 str[i] = 'r'  ,   rl[i]=rl[i-1]+1, bl[i]=0 如果 str[i] = 'b' ,  bl[i]=bl[i-1]+1, rl[i]=0 如果 str[i] = 'w',  bl[i]=b

uva 10154 DP 叠乌龟

题意: 给你几只乌龟,每只乌龟有自身的重量和力量。 每只乌龟的力量可以承受自身体重和在其上的几只乌龟的体重和内。 问最多能叠放几只乌龟。 解析: 先将乌龟按力量从小到大排列。 然后dp的时候从前往后叠,状态转移方程: dp[i][j] = dp[i - 1][j];if (dp[i - 1][j - 1] != inf && dp[i - 1][j - 1] <= t[i]

uva 10118 dP

题意: 给4列篮子,每次从某一列开始无放回拿蜡烛放入篮子里,并且篮子最多只能放5支蜡烛,数字代表蜡烛的颜色。 当拿出当前颜色的蜡烛在篮子里存在时,猪脚可以把蜡烛带回家。 问最多拿多少只蜡烛。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cs

uva 10069 DP + 大数加法

代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <queue>#include <map>#include <cl

uva 10029 HASH + DP

题意: 给一个字典,里面有好多单词。单词可以由增加、删除、变换,变成另一个单词,问能变换的最长单词长度。 解析: HASH+dp 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

XTU 1233 n个硬币连续m个正面个数(dp)

题面: Coins Problem Description: Duoxida buys a bottle of MaiDong from a vending machine and the machine give her n coins back. She places them in a line randomly showing head face or tail face o

dp算法练习题【8】

不同二叉搜索树 96. 不同的二叉搜索树 给你一个整数 n ,求恰由 n 个节点组成且节点值从 1 到 n 互不相同的 二叉搜索树 有多少种?返回满足题意的二叉搜索树的种数。 示例 1: 输入:n = 3输出:5 示例 2: 输入:n = 1输出:1 class Solution {public int numTrees(int n) {int[] dp = new int