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? 如果有的话,输出字典序最小的路径 ...
随机推荐
- 关于python的闭包与装饰器的实验
首先看闭包,在嵌套函数内添加返回值,可以通过外部函数读取内部函数信息 #encoding=utf-8 #闭包应用 #先定义闭包函数,并使用 def outer(func): def inner(): ...
- js中DOM 节点的一些操作方法
什么是DOM DOM:文档对象模型.DOM 为文档提供了结构化表示,并定义了如何通过脚本来访问文档结构.目的其实就是为了能让js操作html元素而制定的一个规范. DOM就是由节点组成的. 解析过程 ...
- kafka常用命令笔记
0.查看有哪些主题: ./kafka-topics.sh --list --zookeeper 192.168.0.201:12181 1.查看topic的详细信息 ./kafka-topics.sh ...
- java设计模式之责任链模式以及在java中作用
责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链.请求在这个链上传递,直到链上的某一个对象决定处理此请求.发出这个请求的客户端并不知道链上的哪一个 ...
- 【集训试题】SiriusRen的卡牌 set
题意概述: 给出N张卡牌,每张有三个属性a,b,c,同时给出所有属性可能的最大值A,B,C.对于一张卡牌,当这张卡牌至少有两个属性大于另外一张卡牌的对应两个属性的时候,认为这张卡牌更加优秀.现在问有多 ...
- PHP 用Symfony VarDumper Component 调试
Symfony VarDumper 类似 php var_dump() 官方文档写的安装方法 : 按照步骤 就可以在 running any PHP code 时候使用了 In order to h ...
- 项目启动报错: No naming context bound to this class loader
发步项目到本地tomcat,启动后,一直包错: 警告: Failed to retrieve JNDI naming context for container [StandardEngine[Ca ...
- 【转】C++ const用法 尽可能使用const
http://www.cnblogs.com/xudong-bupt/p/3509567.html C++ const 允许指定一个语义约束,编译器会强制实施这个约束,允许程序员告诉编译器某值是保持不 ...
- SQL Server 部署CLR程序集错误`6218`
Visual Studio 2015中开发的SQL Server项目,添加了用户自定义函数,需要部署到SQL Server 2005上, 在部署时报错: (70,1): SQL72014: .Net ...
- Sigar应用
sigar是一个用于获取底层硬件信息比如:CPU,内存,硬盘,网络等等信息的库.其官网如下: https://support.hyperic.com/display/SIGAR/Home 出于项目 ...