UVA 10417 Gift Exchanging

#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的更多相关文章
- UVA 10471 Gift Exchanging
题意:就5种盒子,给出每个盒子个数,盒子总数,每个人选择这个盒子的概率.求这个人选择哪个盒子取得第一个朋友的概率最大,最大多少 dp[N][sta]表示当前第N个人面临状态sta(选择盒子的状态可以用 ...
- UVA 10120 - Gift?!(搜索+规律)
Problem D. Gift?! The Problem There is a beautiful river in a small village. N rocks are arranged ...
- UVa 10120 - Gift?!
题目大意 美丽的村庄里有一条河,N个石头被放置在一条直线上,从左岸到右岸编号依次为1,2,...N.两个相邻的石头之间恰好是一米,左岸到第一个石头的距离也是一米,第N个石头到右岸同样是一米.礼物被放置 ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 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, ...
- [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 ...
- USACO . Greedy Gift Givers
Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
随机推荐
- Django_随机验证码
随机验证码 Python生成随机验证码,需要使用PIL模块. 安装: pip3 install pillow 基本使用 1. 创建图片 from PIL import Image img = Imag ...
- LeetCode:寻找数组的中心索引【668】
LeetCode:寻找数组的中心索引[668] 题目描述 给定一个整数类型的数组 nums,请编写一个能够返回数组“中心索引”的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和 ...
- 区块链入门级别认知(blockchain)
区块链入门级别认知(blockchain) 前言:今天参加了迅雷关于区块链的大会,学习和感受总结一下 之前的认知在:几个混迹互联网圈关于区块链 耳熟能详的 热词 “比特币” “区块链” “挖矿” ,知 ...
- javascript;Jquery;获取JSON对象,无刷新评论实例。
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- js判断一个数组是否包含一个指定的值
今天看了一下 有好几种方法 总结一下 1:array.indexOf 此方法判断数组中是否存在某个值,如果存在返回数组元素的下标,否则返回-1 let arr = ['something', ...
- 3.6《深入理解计算机系统》笔记(四)虚拟存储器,malloc,垃圾回收【插图】
概述 ●我们电脑上运行的程序都是使用虚拟存储,跟物理内存根本不搭边. ●既然虚拟内存是在磁盘上的,为什么它又运行这么好,并没有感觉卡顿?这要感谢程序的局部性! ●虚拟存储器的调度是一个操作系统必须做好 ...
- Adroid真机调试
几次想学Android,都因为启动模拟器调试时太慢而放弃. 今天终于搞通了真机调试,记录一下: 1)USB线把手机和电脑连接. 2)Adroid手机启用USB调试. 3)命令行运行 adb devic ...
- mysql启动报can't create/write to file 'var/run/mysqld/mysqld.pid 错误解决办法
msql启动报错,启动不了. 进入mysql日志默认的路径为 /var/log/mysqld.log 查看日志,发现报错信息如下: can't create/write to file 'var/ru ...
- 算法总结之 最大值减去最小值或等于num的子数组数量
给定数组arr和整数num,共返回有多少个子数组满足 <= num 数组长度N 时间复杂度O(N) package TT; import java.util.LinkedList; pu ...
- js实现级联菜单(没有后台)
html代码: <!-- js级联菜单 --> <div id="cascMenu"> <select id="select" o ...