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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 怎么使用pipenv管理你的python项目
原文链接:https://robots.thoughtbot.com/how-to-manage-your-python-projects-with-pipenv 翻译者:Jiong 在thought ...
- Struts2(五.用户注册的实现及整合Action的配置方法)
一.用户注册功能 register.jsp页面 若是jquery ajax方式提交给action,还要回到jquery,控制权在jquery若是表单方式提交给action,控制权交给action &l ...
- 11-Mysql数据库----单表查询
本节重点: 单表查询 语法: 一.单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field ...
- Ruby中数组的&操作
最近在忙一个项目,好久没有写日志了,项目终于接近尾声,可以适当放松一下,所以记一下在这个项目中发现的有趣事情: 数组的 与 操作 一直以为两个数组A和B相与,谁前谁后都一样,不过这次在项目中突然想试一 ...
- BZOJ 4011 HNOI2015 落忆枫音 DAG上的dp(实际上重点在于分析)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4011 题意概述:给出一张N点的DAG(从1可以到达所有的点),点1的入度为0.现在加一条原 ...
- HDU 4722 Good Numbers(位数DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description If we sum up every digit of a number and the result can be exactly divided by 10, we say ...
- video on web
一.video容器 你可能经常看到.avi或.mp4的视频文件,实际上avi或者mp4只是一种视频容器.打个比方,ZIP的压缩文件可以包含各种各样的文件,同理,视频容器也定义用来怎么存放各种 ...
- 如何在MyEclipse下查看JDK源代码
在MyEclipse中查看JDK类库的源代码~ 设置: 1.点 "window"-> "Preferences" -> "Java&quo ...
- [剑指Offer] 17.树的子结构
题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构) [思路]要查找树A中是否存在和树B结构一样的子树,可以分成两步: 1.第一步在树A中找到和B的根节 ...
- 【版本控制】VisualSVN Server更改SVN版本库存放路径的方法
最近也玩起了SVN软件版本管理,在本机上安装了VisualSVN Server+TortoiseSVN,感觉还不错吧.但是,版本库存在哪里呢?在安装VisualSVN Server时,已经默认设置了, ...