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.

Input

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

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.

Examples
input

Copy
2 2
50 2
10 1
output

Copy
1.500000000
input

Copy
2 2
0 2
100 2
output

Copy
1.000000000
input

Copy
3 3
50 3
50 2
25 2
output

Copy
1.687500000
input

Copy
2 2
0 2
0 2
output

Copy
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)的更多相关文章

  1. Codeforces 498B Name That Tune 概率dp (看题解)

    Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...

  2. CodeForces 540D--Bad Luck Island(概率DP)

    貌似竟然是我的第一道概率DP.. 手机码代码真不舒服.... /************************************************ Memory: 67248 KB Ti ...

  3. codeforces 148D Bag of mice(概率dp)

    题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...

  4. CodeForces 24D Broken robot (概率DP)

    D. Broken robot time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

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

  6. Codeforces 148D Bag of mice 概率dp(水

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...

  7. CodeForces 148D-Bag of mice(概率dp)

    题意: 袋子里有w个白球b个黑球,现在两个人轮流每次取一个球(不放回),先取到白球的获胜,当后手取走一个球时,袋子里的球会随机的漏掉一个,问先手获胜的概率. 分析: dp[i][j]表示袋子中i个白球 ...

  8. Codeforces 1151F Sonya and Informatics (概率dp)

    大意: 给定01序列, 求随机交换k次后, 序列升序的概率. 假设一共$tot$个$0$, 设交换$i$次后前$tot$个数中有$j$个$0$的方案数为$dp[i][j]$, 答案即为$\frac{d ...

  9. Codeforces 513G1 513G2 Inversions problem [概率dp]

    转自九野:http://blog.csdn.net/qq574857122/article/details/43643135 题目链接:点击打开链接 题意: 给定n ,k 下面n个数表示有一个n的排列 ...

随机推荐

  1. 多路径路由算法选择(1)——ECMP、WCMP

    不要问为什么,现在的工作转向了网络路由协议的设计. 传统的网络拓朴结构可以形象的表示为树结构,我们称之为“有中心的网络拓扑结构”,简单地认为很多流量请求最终会汇聚到主干网这样的路由中心,才能转发到下一 ...

  2. ZooKeeper与仲裁模式

    为了让服务器之间可以通信,服务器间需要一些联系信息.理论上,服务器可以使用多播来发现彼此,但我们想让ZooKeeper集合支持跨多个网 络而不是单个网络,这样就可以支持多个集合的情况. 为了完成这些, ...

  3. Netty面试题

    1.BIO.NIO和AIO的区别? BIO:一个连接一个线程,客户端有连接请求时服务器端就需要启动一个线程进行处理.线程开销大. 伪异步IO:将请求连接放入线程池,一对多,但线程还是很宝贵的资源. N ...

  4. views获取数据 -- request包含的方法

    request.GET request.POST request.FILES request.path_info request.xxx.getlist request.method request. ...

  5. Java使用 VelocityEngine模板引擎快速生成HTML等各种代码

    https://blog.csdn.net/icannotdebug/article/details/79725297 一.简介 Velocity 是一个基于 Java 的模板引擎框架,提供的模板语言 ...

  6. Redis实战——redis主从复制和集群实现原理

    出自:https://blog.csdn.net/nuli888/article/details/52136822 redis主从复制redis主从配置比较简单,基本就是在从节点配置文件加上:slav ...

  7. 我的MAXSCRIPT笔记

    getnodebyname "circle01" for o in objects do if o.name == "circle01" then select ...

  8. 动态修改datagrid中的numberbox的最大值和最小值

    注意datagrid使用的触发函数是: onBeginEdit,只有在这个触发条件下,editor才真正初始化完成,不然没法动态修改numberbox中的最大最小值. 示例代码:(注意这一块:onBe ...

  9. python 获取当前运行的类名函数名

    import inspect def get_current_function_name(): return inspect.stack()[1][3] class MyClass: def func ...

  10. 《DNA比对》蓝桥杯复赛试题

    题目描述 脱氧核糖核酸即常说的DNA,是一类带有遗传信息的生物大分子.它由4种主要的脱氧核苷酸(dAMP.dGMP.dCMT和dTMP)通过磷酸二酯键连接而成.这4种核苷酸可以分别记为:A.G.C.T ...