uva 12723 概率dp
Dudu is a very starving possum. He currently stands in the first shelf of a fridge. This fridge is
composed of N shelves, and each shelf has a number Qi (1 ≤ i ≤ N) of food. The top shelf, where
Dudu is, is identified by the number 1, and the lowest is identified by number N. Dudu doesn’t eat
more than one food in the same shelf, because he doesn’t want to get noticed. Furthermore, Dudu is
very fat and cannot climb the wall of the fridge to a shelf above — nobody knows how did he end up
in the first shelf. Dudu is also afraid of height, so he is only able to climb down at most K shelves at
a time (if he is at shelf i, he is only able to reach shelves i + 1, i + 2, . . . , i + K). There is a chance
Pj that he chooses to get down from a shelf i to a shelf i + j (1 ≤ j ≤ K). If he tries to go down a
number of shelves that makes him get past the lowest shelf, he gets out of the fridge — he will always
get out of the fridge eventually, because someone left the door open. Each food of shelf i has a number
of calories Ci,j that is absorbed by Dudu in case he eats it, and a probability Xi,j that it is chosen by
Dudu, for j from 1 to Qi
. Dudu starts his journey at shelf 1 and, when he is in a shelf, he will always
choose a food to eat and then will go to another shelf. What is the expected number of calories that
Dudu will absorb by the time he gets out of the fridge?
Input
The first line contains T (T ≤ 100) — the number of test cases, after this line T test cases follows.
The first line of a test case contains two integers, N and K (1 ≤ N ≤ 500; 1 ≤ K ≤ 10) — the
number of shelves in the fridge and the maximum number of shelves Dudu can climb down at a time,
correspondingly. The second line of a test case contains K real numbers Pj , where Pj is the probability
that Dudu goes down j shelves, for j from 1 to K (0 ≤ Pj ≤ 1; ∑K
j=1 Pj = 1). Each of the next N
lines of a test case describes a shelf (from the shelf 1 to shelf N). Each line starts with a integer Qi
(1 ≤ Qi ≤ 20), which is the amount of food existent is in this shelf. Qi pair follows, each pair containing
2 real numbers Ci,j and Xi,j (0 ≤ Ci,j ≤ 100; 0 ≤ Xi,j ≤ 1; ∑Qi
j=1 Xi,j = 1).
Output
For each test case print a line containing ‘Case #X: Y ’, where X is the case number, starting at 1,
and Y is the expected number of calories that Dudu will absorb by the time he gets out of the fridge.
Y should be rounded up to 6 digits after the decimal point.
Sample Input
2
2 1
1.0
2 50 0.5 100 0.5
2 10 0.5 20 0.5
5 2
0.3 0.7
5 10 0.2 20 0.3 5 0.1 25 0.35 2 0.05
2 20 0.4 40 0.6
1 4 1.0
3 30 0.8 3 0.1 4 0.1
10 1 0.1 2 0.1 3 0.1 4 0.1 5 0.1 6 0.1 7 0.1 8 0.1 9 0.1 10 0.1
Sample Output
Case #1: 90.000000
Case #2: 44.929950
题目大意:已知老鼠在第一层,只能往下走走到第n层结束。在第i层时可以走i+1、i+2、....、i+k,选择第i+j层的概率是Pj(1<=<=k)。每层有若干食物包括选它的概率跟它所含的卡路里,老鼠会选一种食物吃。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 100007 double ex[];
double dp[];
double pk[];
double C[][],X[][];
double sum[]; int main()
{
int t,cs = ,i,j,k;
int n,m,K,Q;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&K);
for(i=;i<=K;i++)
scanf("%lf",&pk[i]);
for(i=;i<=n;i++)
{
scanf("%d",&Q);
ex[i] = 0.0;
for(j=;j<=Q;j++)
{
scanf("%lf%lf",&C[i][j],&X[i][j]);
ex[i] += C[i][j]*X[i][j];
}
}
memset(dp,,sizeof(dp));
dp[] = ; //dp is probability
for(i=;i<=n;i++)
{
for(k=;k<=K;k++)
{
if(i-k >= )
dp[i] += dp[i-k]*pk[k];
}
}
double res = ;
for(i=;i<=n;i++)
res += dp[i]*ex[i];
printf("Case #%d: %.6lf\n",cs++,res);
}
return ;
}
uva 12723 概率dp的更多相关文章
- UVA 11427 (概率DP+期望)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 题目大意:每晚打游戏.每晚中,赢一局概率p,最多玩n局, ...
- [uva 11762]Race to 1[概率DP]
引用自:http://hi.baidu.com/aekdycoin/item/be20a91bb6cc3213e3f986d3,有改动 题意: 已知D, 每次从[1,D] 内的所有素数中选择一个Ni, ...
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
题意:某个人每天晚上都玩游戏,如果第一次就䊨了就高兴的去睡觉了,否则就继续直到赢的局数的比例严格大于 p,并且他每局获胜的概率也是 p,但是你最玩 n 局,但是如果比例一直超不过 p 的话,你将不高兴 ...
- UVA 10900 So you want to be a 2n-aire? (概率dp)
题意:玩家初始的金额为1:给出n,表示有n道题目:t表示说答对一道题目的概率在t到1之间均匀分布. 每次面对一道题,可以选择结束游戏,获得当前奖金:或者回答下一道问题,答对的话奖金翻倍,答错的话结束游 ...
- Substring UVA - 11468 AC自动机+概率DP
题意: 给出一些字符和各自对应的选择概率,随机选择L次后得到一个长度为L的随机字符串S. 给出K个模板串,计算S不包含任何一个模板串的概率 dp[i][j]表示走到AC自动机 i 这个节点 还需要走 ...
- 概率dp专辑
求概率 uva11021 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- DP专题之概率DP
注意:在概率DP中求期望要逆着推,求概率要正着推 概率DP求期望: 链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 dp[ i ]表示从i点走到n ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
随机推荐
- vim 自动补全 颜色设置
vim 自动补全 颜色设置 hi Pmenu ctermfg=black ctermbg=gray guibg=# hi PmenuSel ctermfg= ctermbg= guibg=# guif ...
- RabbitMQ 学习资料
https://www.rabbitmq.com/getstarted.html http://www.cnblogs.com/luxiaoxun/p/3918054.html http://back ...
- Nuget使用备忘
菜单:工具-库程序包管理器-管理解决方案的NuGet程序包,搜索,下载,安装 或者 工具-库程序包管理器-程序包管理器控制台,输入PM命令,如: install-package log4net 如果不 ...
- 学习JavaScript你必须掌握的8大知识点!
大知识点! 一.JavaScript思维导图之<变量>的学习 二. JavaScript思维导图之<函数基础> 三.JavaScript思维导图之<基本dom操作 ...
- python3和Python2的区别
一.print函数 python2 的 print 声明已经被 print() 函数取代了,这意味着我们必须包装我们想打印在小括号中的对象 二.通过input()解析用户的输入 python3中inp ...
- Unity基础-脚本的优化
脚本的优化 object pool 避免频繁的内存分配和gc噩梦(字符串相加?) 是否有必要都写在update里?分帧? 需要的只取一次 使用editor内赋值,而不是find 复杂的物理 复杂的数学 ...
- destoon 短信发送函数及短信接口修改
// $DT在common.inc.php中定义, $CACHE = cache_read('module.php'); $DT = $CACHE['dt']; 从缓存里读取网站配置信息. //$d ...
- MyBatis的增删改查操作
搭建好mybatis之后 进行对数据库的操作 添加语句 在映射文件中添加语句 insert into student(name,age,score) values(#{name},#{age},#{s ...
- 有关Kali的方法
Kali 找回系统登陆密码的方式:https://jingyan.baidu.com/article/47a29f24560e77c0142399e3.html
- 按键精灵安卓版 tap、touch命令 不好用的解决办法!
用按键精灵手机版写脚本来操作新浪微博APP,在关注列表页自动取消关注,代码如下: If x > -1 And y > -1 Then delay 1000 tap x,y delay 10 ...