CodeForces 499D. Name That Tune(概率dp)
It turns out that you are a great fan of rock band AC/PE. Peter learned that and started the following game: he plays the first song of the list of n songs of the group, and you have to find out the name of the song. After you tell the song name, Peter immediately plays the following song in order, and so on.
The i-th song of AC/PE has its recognizability pi. This means that if the song has not yet been recognized by you, you listen to it for exactly one more second and with probability of pi percent you recognize it and tell it's name. Otherwise you continue listening it. Note that you can only try to guess it only when it is integer number of seconds after the moment the song starts playing.
In all AC/PE songs the first words of chorus are the same as the title, so when you've heard the first ti seconds of i-th song and its chorus starts, you immediately guess its name for sure.
For example, in the song Highway To Red the chorus sounds pretty late, but the song has high recognizability. In the song Back In Blue, on the other hand, the words from the title sound close to the beginning of the song, but it's hard to name it before hearing those words. You can name both of these songs during a few more first seconds.
Determine the expected number songs of you will recognize if the game lasts for exactly T seconds (i. e. you can make the last guess on the second T, after that the game stops).
If all songs are recognized faster than in T seconds, the game stops after the last song is recognized.
The first line of the input contains numbers n and T (1 ≤ n ≤ 5000, 1 ≤ T ≤ 5000), separated by a space. Next n lines contain pairs of numbers pi and ti (0 ≤ pi ≤ 100, 1 ≤ ti ≤ T). The songs are given in the same order as in Petya's list.
Output a single number — the expected number of the number of songs you will recognize in T seconds. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
2 2
50 2
10 1
1.500000000
2 2
0 2
100 2
1.000000000
3 3
50 3
50 2
25 2
1.687500000
2 2
0 2
0 2
1.000000000 题意:给出n首歌,每首歌长度为t[i]分钟,在歌曲播放的每分钟里都有p[i]的概率猜出歌名,如果猜出就会跳下一首,否则等这首歌放完了也会切下一首,求T秒时听歌数的期望。
题解:令dp[i][j]表示第j分钟恰好听出第i首歌的概率,那么答案就是所有的dp[i][j](i<=n,j<=t)之和
考虑转移:
这首歌在第j秒听完的概率只会从他之前t[i]秒转移过来,所以dp的转移如下
dp[i][j]=∑(dp[i-1][j-k]*(1-p[i])^(k-1)*p[i])+dp[i][j-t[i]]*(1-p[i])^(t[i]-1)(k<t[i]); 代码如下:
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; double dp[][],p[];
int n,t,tt[]; double kasumi(double a,int b)
{
double ans=1.0;
while(b)
{
if(b&)
{
ans=ans*a;
}
a=a*a;
b>>=;
}
return ans;
} int main()
{
scanf("%d%d",&n,&t);
for(int i=;i<=n;i++)
{
scanf("%lf%d",&p[i],&tt[i]);
p[i]/=;
}
dp[][]=;
double ans=0.0;
for(int i=;i<=n;i++)
{
double sum=;
double kth=kasumi(-p[i],tt[i]-);
for(int j=;j<=t;j++)
{
sum*=-p[i];
sum+=dp[i-][j-]*p[i];
if(j>=tt[i])
{
sum-=dp[i-][j-tt[i]]*kth*p[i];
dp[i][j]+=dp[i-][j-tt[i]]*kth;
}
dp[i][j]+=sum;
ans+=dp[i][j];
}
}
printf("%.6lf\n",ans);
}
CodeForces 499D. Name That Tune(概率dp)的更多相关文章
- Codeforces 498B Name That Tune 概率dp (看题解)
Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...
- CodeForces 540D--Bad Luck Island(概率DP)
貌似竟然是我的第一道概率DP.. 手机码代码真不舒服.... /************************************************ Memory: 67248 KB Ti ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- CodeForces 24D Broken robot (概率DP)
D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]
D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- CodeForces 148D-Bag of mice(概率dp)
题意: 袋子里有w个白球b个黑球,现在两个人轮流每次取一个球(不放回),先取到白球的获胜,当后手取走一个球时,袋子里的球会随机的漏掉一个,问先手获胜的概率. 分析: dp[i][j]表示袋子中i个白球 ...
- Codeforces 1151F Sonya and Informatics (概率dp)
大意: 给定01序列, 求随机交换k次后, 序列升序的概率. 假设一共$tot$个$0$, 设交换$i$次后前$tot$个数中有$j$个$0$的方案数为$dp[i][j]$, 答案即为$\frac{d ...
- Codeforces 513G1 513G2 Inversions problem [概率dp]
转自九野:http://blog.csdn.net/qq574857122/article/details/43643135 题目链接:点击打开链接 题意: 给定n ,k 下面n个数表示有一个n的排列 ...
随机推荐
- 改变checkbox的背景颜色
input:checked{-webkit-appearance:none;background-color: #f4a100;}
- 08_java超市管理系统
超市管理系统功能介绍 * A:超市管理系统功能介绍 * a: 显示主菜单 ============欢迎光临ItCast超市============ 1: 货物 清单 2: 添加货物 3: 删除货物 4 ...
- nginx的下载和安装
安装 下载必要组件 nginx下载地址 http://nginx.org/en/download.html pcre库下载地址,nginx需要[解析正则] http://sourceforge.ne ...
- 关于jquery中的parent的认定
<li><label class='checkbox inline'><input type='checkbox' name='type[]' value='{$item ...
- 「小程序JAVA实战」小程序的基础组件(24)
转自:https://idig8.com/2018/08/12/xiaochengxu-chuji-24/ 来说下 ,小程序的基础组件.源码:https://github.com/limingios/ ...
- centOS安装openoffice的方法
centOS安装openoffice的方法 分类: centOS 2012-06-15 10:24 2872人阅读 评论(0) 收藏 举报 centos测试 yum install openoffic ...
- javaWeb 开发的成长路线
感觉最近技术到了一个瓶颈,好长时间没有感觉进步了,本着活到老学到老的态度,笔者就去逛了下,看看前辈们写的文章,觉得他们写的非常不错,在这里特别贴出一张特别值得收藏的图片,不是说其他总结的图片不值得收藏 ...
- iPhone开发随想:rand()还是arc4random()
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://bj007.blog.51cto.com/1701577/544006 今天在iP ...
- Apache Hive (三)Hive元数据信息对应MySQL数据库表
转自:https://www.cnblogs.com/qingyunzong/p/8710356.html 概述 Hive 的元数据信息通常存储在关系型数据库中,常用MySQL数据库作为元数据库管理. ...
- 用C语言进行最基本的socket编程
什么是socket 你经常听到人们谈论着 “socket”,或许你还不知道它的确切含义.现在让我告诉你:它是使用 标准Unix 文件描述符 (file descriptor) 和其它程序通讯的方式.什 ...