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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- Swift中字典解析后的问题,!?两种拆包的差别
给出一个json,使用SwiftyJSON解析传给model,传进去是个字典,字典里有String,NSNumber,NSDoctionary,和NSArray. 正常情况下直接使用下面的解析方法即可 ...
- 快速查找文件——Everything
Everything Search Engine Locate files and folders by name instantly. Small installation file Clean a ...
- php token 生成
php token的生成 接口特点汇总: 1.因为是非开放性的,所以所有的接口都是封闭的,只对公司内部的产品有效: 2.因为是非开放性的,所以OAuth那套协议是行不通的,因为没有中间用户的授权过 ...
- Linux Shell基础 通配符
通配符 在 Bash 中,如果需要模糊匹配文件名或目录名,就要用到通配符.下面为常用的通配符. 表 1 通配符 通配符 作 用 ? 匹配一个任意字符 * 匹配 0 个或任意多个任意字符,也就是可以匹配 ...
- 【HackerRank】The Love-Letter Mystery
James找到了他的朋友Harry要给女朋友的情书.James很爱恶作剧,所以他决定要胡搞一下.他把信中的每个单字都变成了回文.对任何给定的字符串,他可以减少其中任何一个字符的值,例如'd'可以变成' ...
- python中偏函数
当一个函数有很多参数时,调用者就需要提供多个参数.如果减少参数个数,就可以简化调用者的负担. 比如,int()函数可以把字符串转换为整数,当仅传入字符串时,int()函数默认按十进制转换: >& ...
- C#多线程学习之Thread
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- Druid数据库连接池的一般使用
据说:阿里的Druid这款产品,是目前最好用的数据库池产品,下面就来看下怎么在我们项目中去使用它吧. 项目背景:使用的是SpringMvc+Spring+mybatis 在ssm框架里面使用数据连接池 ...
- easyui控件使用例子
1.easyui之dataGrid分页加载数据例子 注意:1)分页表格通过url获得数据会提交page,rows两个参数:后台需要获取这两个参数并且由此得到 int pageSize=rows/pag ...
- Java基础(7)-集合类3
list集合的特点 1)有序(存储和取出的元素一直) 2)可重复 List子类的特点 ArrayList 有序,可重复 底层数据结构是数组 查询快,增删慢 线程不安全,效率高 Vector 有序,可重 ...