#include <iostream>
#include <cstring>
#include <stdio.h>
#include <math.h>
#define N 12
using namespace std; int n;
int expect[]; //5种礼物的实际数量
double p[N][];
double first[]; void Input()
{
int i,j;
scanf("%d", &n);
for(j=;j<=;j++)
{
scanf("%d", &expect[j]);
}
for(i=;i<n;i++)
{
for(j=;j<=;j++)
{
scanf("%lf", &p[i][j]);
}
}
memset(first,,sizeof(first));
} double dfs(int g, double c)
{
if(g==n)
return c;
double t;
double ans=;
for(int i=;i<=;i++)
{
if(expect[i]&&fabs(p[g][i])>1e-)
{
expect[i]--;
t = dfs(g+, c*p[g][i]);
if(g==)
first[i]+=t;
expect[i]++;
ans+=t;
}
}
return ans;
} void Do(double s)
{
int x;
double v=;
for(int i=;i<=;i++)
{
if(first[i]/expect[i]-v > 1e-)
{
x=i;
v=first[i]/expect[i];
}
}
printf("%d %.3lf\n",x,v/s);
} int main()
{
int t;
double s;
scanf("%d", &t);
while(t--)
{
Input();
s=dfs(, );
Do(s);
}
return ;
}

UVA 10417 Gift Exchanging的更多相关文章

  1. UVA 10471 Gift Exchanging

    题意:就5种盒子,给出每个盒子个数,盒子总数,每个人选择这个盒子的概率.求这个人选择哪个盒子取得第一个朋友的概率最大,最大多少 dp[N][sta]表示当前第N个人面临状态sta(选择盒子的状态可以用 ...

  2. UVA 10120 - Gift?!(搜索+规律)

     Problem D. Gift?!  The Problem There is a beautiful river in a small village. N rocks are arranged ...

  3. UVa 10120 - Gift?!

    题目大意 美丽的村庄里有一条河,N个石头被放置在一条直线上,从左岸到右岸编号依次为1,2,...N.两个相邻的石头之间恰好是一米,左岸到第一个石头的距离也是一米,第N个石头到右岸同样是一米.礼物被放置 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)

    Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...

  6. [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]

    11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...

  7. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. mysql用户管理(新增用户及权限管理)

    一.登录: # mysql  –u  root  –p  回车输入密码 退出: #exit; 二.修改密码: 格式:mysqladmin  –u 用户名 –p旧密码  password  新密码 # ...

  2. Python基础知识补充(重要)-作用域、特殊语法

    Python作用域 python代码内部块如if语句内声明变量,在if代码段后在调用此变量并未报如“undefinded name"此类错误,例子如下: if 1 == 1: name = ...

  3. 分享几个基于 Yii2 的开源项目

    Yii2 Starter Kit(Yii2 开箱即用):https://github.com/trntv/yii2-starter-kit GetYii:https://github.com/iiYi ...

  4. springboot打war包

    修改pom为war不是jar. 移除tomcar的jar依赖: <dependency> <groupId>org.springframework.boot</group ...

  5. springboot-FilterRegistrationBean

    主要用来对servlet filter进行自定义,比如设置order. 先写一个普通的filter: public class FilterDemo implements Filter { priva ...

  6. Delphi中ComPort通信中的数据处理

    源: Delphi中ComPort通信中的数据处理

  7. AJAX跨域资源共享 CORS 详解

    CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing). 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从 ...

  8. nohup后台运行jar与关闭

    nohup 用途:LINUX命令用法,不挂断地运行命令.  语法:nohup Command [ Arg ... ] [ & ]  描述:nohup 命令运行由 Command 参数和任何相关 ...

  9. 手动用maven安装jar的命令

    手动用maven安装jar的命令: mvn install:install-file -DgroupId=com.oracle.jdbc -DartifactId=ojdbc5 -Dversion=1 ...

  10. winform获取文件路径

    1.取得控制台应用程序的根目录方法     方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径     方法2.AppDomain.CurrentD ...