UVA 10471 Gift Exchanging
题意:就5种盒子,给出每个盒子个数,盒子总数,每个人选择这个盒子的概率。求这个人选择哪个盒子取得第一个朋友的概率最大,最大多少
dp[N][sta]表示当前第N个人面临状态sta(选择盒子的状态可以用13进制数表示)时的概率,
那么转移就是dp[N][sta]=sum(dp[N-1][sta-1]*G[n][k]) (表示第N个人选择第k个盒子)
那么答案应该是max(P(第1个人选择i号盒子)/总状态概率)(i<=5)
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
#define MAXN 350000
#define MAXD 15
#define MAXB 10
double p[MAXD][MAXB],dp[MAXD][MAXN];
bool vis[MAXD][MAXN];
int N,res[MAXB],gift[MAXB];
double calcu(int cur,int st)
{
if (vis[cur][st]) return dp[cur][st];
vis[cur][st]=true;
double ans=;
int sta=st;
for (int i=;i>;i--) {res[i]=sta%;sta/=;}
for (int i=;i<=;i++)
if (res[i])
{
res[i]--;
sta=;
for (int j=;j<=;j++) sta=sta*+res[j];
ans+=calcu(cur+,sta)*p[cur][i];
res[i]++;
}
return dp[cur][st]=ans;
}
int main()
{
//freopen("sample.txt","r",stdin);
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&N);
int sta=;
for (int i=;i<=;i++) { scanf("%d",&gift[i]);sta=sta*+gift[i];}
for (int i=;i<=N;i++) for (int j=;j<=;j++) scanf("%lf",&p[i][j]);
memset(vis,false,sizeof(vis));
vis[N+][]=true;dp[N+][]=;
double tmp=calcu(,sta);
double ans=-1.0,sym;int ide;
for (int i=;i<=;i++)
if (gift[i])
{
gift[i]--;
sta=;
for (int j=;j<=;j++) sta=sta*+gift[j];
gift[i]++;
sym=dp[][sta]*p[][i]/gift[i];
if (sym/tmp>ans)
{
ans=sym/tmp;
ide=i;
}
}
printf("%d %.3lf\n",ide,ans);
}
return ;
}
UVA 10471 Gift Exchanging的更多相关文章
- UVA 10417 Gift Exchanging
#include <iostream> #include <cstring> #include <stdio.h> #include <math.h> ...
- 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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- P2384洛谷 最短路
题目描述 给定n个点的带权有向图,求从1到n的路径中边权之积最小的简单路径. 输入输出格式 输入格式: 第一行读入两个整数n,m,表示共n个点m条边. 接下来m行,每行三个正整数x,y,z,表示点x到 ...
- [转]学习win10的bash使用ssh连接远程服务器
1. 前言 微软已经在Win10一周年更新预览版中加入了Ubuntu Bash命令支持,相当于一个小型的linux系统,本来连接远程服务器的话,要使用putty啥的,现在可以用这个直接连接,我来讲讲步 ...
- IDEA无法新建GUI Form文件
因为最近想开发一个IDEA的插件,所以在开发的过程中就需要创建Swing GUI Form文件.但是在项目中右键New中始终就是没有“GUI Form”这个选项,然后自己琢磨寻思着是不是没有启用Swi ...
- Javascript Array和String的互转换
Array类可以如下定义: var aValues = new Array(); 如果预先知道数组的长度,可以用参数传递长度 var aValues = new Array(20); -------- ...
- Java循环控制语句-switch
Java循环控制语句之一switch 不同于其他循环控制语句的特性: switch的英文解释为开关,正如它的解释一样,switch循环的特点就像开关一样,跳到哪一个条件即会出现某一种结果. 写法: s ...
- delphi数据库进行增加操作时,怎么判断插入的这个值是否已经存在?
//增 procedure TForm1.btnAddClick(Sender: TObject); begin ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQu ...
- 【其他】Windows 系统安装IIS 打开页面出现空白解决方案
部署IIS过程中遇到了一个奇怪的问题,就是怎么设置打开的页面都是一篇空白,IIS也没有任何报错,翻遍互联网好不容易找到了解决方法,今天就教给大家,希望大家不要走弯路.此方法Windows xp.7.8 ...
- 使用POI操作Excel
首先要下载所需jar包, 官网:http://poi.apache.org ,POI支持office的所有版本 下载完后,打开“poi-bin-3.10.1-20140818”获取操作excel需要的 ...
- 【bzoj1787】[Ahoi2008]Meet 紧急集合 倍增LCA
题目描述 输入 输出 样例输入 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 3 1 2 4 4 6 6 6 样例输出 5 2 2 5 4 1 6 0 题解 倍增LCA 首先有集合点 ...
- AGC017D Game on Tree(树型博弈)
题目大意: 给出一棵n个结点的树,以1为根,每次可以切掉除1外的任意一棵子树,最后不能切的话就为负,问是先手必胜还是后手必胜. 题解: 首先我们考虑利用SG函数解决这个问题 如果1结点有多个子节点,那 ...