题意:就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的更多相关文章

  1. UVA 10417 Gift Exchanging

    #include <iostream> #include <cstring> #include <stdio.h> #include <math.h> ...

  2. UVA 10120 - Gift?!(搜索+规律)

     Problem D. Gift?!  The Problem There is a beautiful river in a small village. N rocks are arranged ...

  3. UVa 10120 - Gift?!

    题目大意 美丽的村庄里有一条河,N个石头被放置在一条直线上,从左岸到右岸编号依次为1,2,...N.两个相邻的石头之间恰好是一米,左岸到第一个石头的距离也是一米,第N个石头到右岸同样是一米.礼物被放置 ...

  4. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  5. 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, ...

  6. [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 ...

  7. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. CSS3 : transition 属性

    CSS3的 transition 属性用于状态过度效果! 1.语法: transition: property duration timing-function delay; -moz-transit ...

  2. 问题 C: 质因数的个数

    1947: 质因数的个数 时间限制: 1 Sec  内存限制: 32 MB提交: 245  解决: 114[提交][状态][讨论版][命题人:外部导入] 题目描述 求正整数N(N>1)的质因数的 ...

  3. truffle自动化测试脚本

    truffle自动化测试脚本 补充一个unbox 1.部署本地ganache环境 配置文件地址为本地地址 localhost:XXXX 上线的环境为 infura的url 2.命令: truffle ...

  4. System.NullReferenceException:未将对象引用设置到对象的实例,这是一个新鸟,中鸟,老鸟都避不开的错误

    原文链接:http://www.jb51.net/article/30005.htm

  5. window下对samba的清理操作

    windows清除访问samba局域网密码缓存 1.在dos窗口中输入control userpasswords2或者control keymgr.dll,然后[高级]/[密码管理],删掉保存的该机器 ...

  6. java线程(4)——线程同步的锁技术

    同步 同步,字面来看,有点一起工作的意思.但在线程同步中,"同"意为协同.互相配合. 比如: A.B两个线程,并不是说两个线程必须同时一起工作,而是说互相配合工作,在某个时间可能线 ...

  7. QThread中的互斥、读写锁、信号量、条件变量

    该文出自:http://www.civilnet.cn/bbs/browse.php?topicno=78431 在gemfield的<从pthread到QThread>一文中我们了解了线 ...

  8. javascript string对象方法replace

    最简单的replace用法是: var str = 'aaaaa9876b0000'; str.replace(/a/g,'A'); 有时候我们希望只是在匹配的位置添加特定的字符: var str = ...

  9. 【python】Python中给List添加元素的4种方法分享

    List 是 Python 中常用的数据类型,它一个有序集合,即其中的元素始终保持着初始时的定义的顺序(除非你对它们进行排序或其他修改操作). 在Python中,向List添加元素,方法有如下4种方法 ...

  10. thead tfoot tbody标签的使用

    这三个都是<body>元素的子标签,不常用,因为其只是对<tr>标签做了一个区分 <thread>用于包裹表格头信息 <tfoot>用于包裹表格最后一行 ...