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的排列 ...
随机推荐
- Math对象及相关方法
Math.abs() 取绝对值 Math.ceil()向上取整 (出现小数点就向上+1) Math.floor()向下取整 Math.round()四舍五入 Math.max(val1,val2,va ...
- cocos2dx 3.6版本播放动画
IDE: VS2013 版本:cocos2dx 3.3.6 语言:c++ 11 3.x版本改动与2.x版本相比改动很大,几个比较明显的点就是所有带cc的前缀没有了,然后一些获取类型的函数名称加了get ...
- java.lang.NoClassDefFoundError: org/jaxen/JaxenException解决方法
在使用dom4j的xpath时出现java.lang.NoClassDefFoundError: org/jaxen/JaxenException的异常,原因是dom4j引用了jaxen jar包,而 ...
- leetcode168
public class Solution { private string Convert(int k) { var s = ""; switch (k) { : s = &qu ...
- iOS 上的蓝牙框架 - Core Bluetooth for iOS
原文: Core Bluetooth for iOS 6 Core Bluetooth 是在iOS5首次引入的,它允许iOS设备可以使用健康,运动,安全,自动化,娱乐,附近等外设数据.在iOS 6 中 ...
- Uniform & Attribute & Varying
[Uniform & Attribute & Varying] 顶点着色器的输入变量用关键字“attribute”来限定. 片段着色器的输入变量(它和顶点着色器的输出变量相对应)用关键 ...
- 【LA2531 训练指南】足球联赛 【最大流】
题意: 有n支队伍进行比赛,每支队伍需要打的比赛数目相同.每场比赛恰好一支队伍胜,另一支败.给出每支队伍目前胜的场数和败的场数,以及每两支队伍还剩下的比赛场数,确定所有可能的冠军的球队.(获胜场数最多 ...
- 111. Minimum Depth of Binary Tree (Tree; DFS)
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- mybatis+oracle如何批量执行多条update
接口 public void setStatus(List<Columns> columnsList); mapping xmlmapping 中使用foreach,关于标签的使用,资料非 ...
- 714. Best Time to Buy and Sell Stock with Transaction Fee有交易费的买卖股票
[抄题]: Your are given an array of integers prices, for which the i-th element is the price of a given ...