B. Name That Tune
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
2 2
50 2
10 1
output
1.500000000
input
2 2
0 2
100 2
output
1.000000000
input
3 3
50 3
50 2
25 2
output
1.687500000
input
2 2
0 2
0 2
output
1.000000000

【分析】

  这题感觉挺难想的啊?

  f[i][j]表示j秒的时候正在听第i首歌(前面的认出来,i正在听)的概率。

  不考虑t[i]的时候是f[i][j]=f[i-1][j-1]*p[i-1]+f[i][j-1]*(1-p[i])

  考虑了t[i]说明f[i][j]不会转到f[i][j+t[i]]而是f[i+1][j]

  所以特判这一部分的转移。

  【然后比较迷人的一点是要用“错的f更新f”?】

  其实正确的转移状态应该是f[i][j]->f[i][j+k](1<=k<t[i])

  但是每次只加一然后累计过去的话少一重循环,说明了f还是一个运输工具【可以这样说吧?不断向j+1的地方运输嘛。。

  你的f还有别人那里运过来的东西,应该由别人累计减掉,你只应该减掉你自己那部分,所以要用g记录,用g更新【我只能这样理解这一层了

  最后加一首歌,若正在播这首说明前一秒已认出前面的所有歌。

  可以模这个题解:http://blog.csdn.net/clove_unique/article/details/62089010

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 5010 double p[Maxn];
int t[Maxn];
double f[Maxn][Maxn],g[Maxn]; double qpow(double p,int b)
{
double ans=1.0;
while(b)
{
if(b&) ans*=p;
p*=p;
b>>=;
}
return ans;
} int main()
{
int n,T;
scanf("%d%d",&n,&T);
for(int i=;i<=n;i++)
{
scanf("%lf%d",&p[i],&t[i]);
p[i]/=100.0;
}
f[][]=;p[n+]=;t[n+]=;
for(int i=;i<=n+;i++)
{
double P=qpow(-p[i],t[i]);
for(int j=;j<=T+;j++) g[j]=f[i][j];
for(int j=;j<=T+;j++)
{
f[i][j+]+=f[i][j]*(-p[i]);
f[i+][j+]+=f[i][j]*p[i];
if(j+t[i]<=T+)
{
f[i][j+t[i]]-=g[j]*P;
f[i+][j+t[i]]+=g[j]*P;
}
}
}
double ans=;
for(int i=;i<=n+;i++) ans+=f[i][T+]*(i-);
printf("%.9lf\n",ans);
return ;
}

2017-04-22 08:05:14

【Codeforces 498B】 B. Name That Tune (概率DP)的更多相关文章

  1. Codeforces 678E. Another Sith Tournament(概率DP,状压)

    Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...

  2. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

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

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

  4. 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 followi ...

  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 167B Wizards and Huge Prize(概率dp)

    题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...

  8. Codeforces 601C Kleofáš and the n-thlon 概率dp

    Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...

  9. Codeforces 280C Game on tree【概率DP】

    Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...

  10. codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)

    题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...

随机推荐

  1. Python概念-禁锢术之__slots__

    之所以给它起名为禁锢术,并非空缺来风,下面我们来了解一下__slost__ __slost__:其实就是将类中的名称锁定,实例化对象,只可以赋值和调用,不可以删除名字和增加新的名字 代码示例:(实例化 ...

  2. 【译】第十五篇 Integration Services:SSIS参数

    本篇文章是Integration Services系列的第十五篇,详细内容请参考原文. 简介在前一篇,我们使用SSDT-BI将第一个SSIS项目My_First_SSIS_Project升级/转换到S ...

  3. 工具推荐:ATSCAN,功能强大的Perl脚本扫描器

    工具推荐:ATSCAN,功能强大的Perl脚本扫描器 使用perl语言编写的开源的扫描器,功能丰富强大,除了基本的tcp和udp端口扫描之外,还可以搜索wordpress.joomla等网站并进行口令 ...

  4. beego项目运行过程

    一:首先man.go,整个程序的入口 func main() { beego.Run() } 然后beego.run()代码 // Run beego application. // beego.Ru ...

  5. Ping程序的实现

    Ping程序的实现 在windows系统下进行cmd可以进行ping操作. ping命令是用来确定本地主机与网络中其他主机的网络通信情况,或者查看是否是为效IP. ping的工作原理:网络另一主机发送 ...

  6. 莫烦课程Batch Normalization 批标准化

    for i in range(N_HIDDEN): # build hidden layers and BN layers input_size = 1 if i == 0 else 10 fc = ...

  7. java浅复制与深使用接口实现

    1.浅复制与深复制概念⑴浅复制(浅克隆)被复制对象的所有变量都含有与原来的对象相同的值,而所有的对其他对象的引用仍然指向原来的对象.换言之,浅复制仅仅复制所考虑的对象,而不复制它所引用的对象. ⑵深复 ...

  8. vue全面介绍--全家桶、项目实例

    简介 “简单却不失优雅,小巧而不乏大匠”. 2016年最火的前端框架当属Vue.js了,很多使用过vue的程序员这样评价它,“vue.js兼具angular.js和react.js的优点,并剔除了它们 ...

  9. php rabbitmq的扩展

    1.下载:https://github.com/alanxz/rabbitmq-c/archive/v0.9.0.tar.gz mkdir build && cd build # 这一 ...

  10. Unix IPC之共享内存区(1)

    1 共享内存区 共享内存区是可用IPC形式中最快的,只有映射和解除映射需要进入内核的系统调用,映射后对共享内存区的访问和修改不再需要系统调用(内核只要负责好页表映射和处理页面故障即可),但通常需要同步 ...