#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. 【HackerRank】 Game Of Thrones - I

    King Robert has 7 kingdoms under his rule. He gets to know from a raven that the Dothraki are going ...

  2. 在vim下按ctrl+s后界面卡住

    用惯了window编辑器的我们,在使用linux vim编辑器时会不会遇到这个问题:在编辑时总是会不小心按下Ctrl+S,然后整个终端都没有反应了?其实在Linux下 Ctrl+S是有特殊的用途的,不 ...

  3. 基于Visual c++ 2012的php扩展开发 - HelloWord!

    1.cmd进入命令行模式,并进入php-5.6.20-src/ext源代码的ext目录下输入命令php ext_skel_win32.php --extname=HelloWord,执行结果如下图: ...

  4. Device Tree(一):背景介绍【转】

    本文转载自:http://www.wowotech.net/device_model/why-dt.html 一.前言 作为一个多年耕耘在linux 2.6.23内核的开发者,各个不同项目中各种不同周 ...

  5. linux 上传scp 压缩tar命令

    1.Linux 上传scp 1)上传文件与文件夹 scp file weblogic@xx.xxx.xxx.xxx:~/songjd/ scp -r filefolder weblogic@xxx.x ...

  6. 【算法】fhqtreap初探

    NOIP回来就一直想着学平衡树...平衡树写久了调不出来真的会头脑发热.jpg 大概只写了几道题... fhqtreap是不需要旋转的平衡树,仅使用分裂合并,一样可以保持平衡树的性质,并且可以非常简单 ...

  7. mac下查看占用端口的进程及杀死进程

    mac lsof -i :9000 kill -9 716

  8. kafka笔记(一)

    1.kafka应用场景 基于流数据的发布订阅消息系统.实时流数据的高效异步通信.基于流数据的高可用分布式存储! 不同的系统之间实时流数据管道; 2.官方一句话概括 kafka是一个分布式流数据平台:可 ...

  9. HDFS文件访问权限

    HDFS中的文件访问权限 针对文件和目录,HDFS的权限模式与POSIX非常相似一共提供三类权限模式:只读权限(r).写入权限(w)和可执行权限(x).读取文件或列出目录内容时需要只读权限.写入一个文 ...

  10. 【转】Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...