【Codeforces 498B】 B. Name That Tune (概率DP)
B. Name That Tunetime limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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.
OutputOutput 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.
Examplesinput2 2
50 2
10 1output1.500000000input2 2
0 2
100 2output1.000000000input3 3
50 3
50 2
25 2output1.687500000input2 2
0 2
0 2output1.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)的更多相关文章
- Codeforces 678E. Another Sith Tournament(概率DP,状压)
Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...
- Codeforces B. Bad Luck Island(概率dp)
题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 498B Name That Tune 概率dp (看题解)
Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...
- 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 ...
- 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 167B Wizards and Huge Prize(概率dp)
题意: n个人,开始有一个容量为k得背包,击败一个人背包可以获得一定容量或得到一个财富(放入背包内),给出击败每个人的概率,求至少击败l个人,且背包容量大于获得的总财富值的概率 分析: 状态好确定,d ...
- Codeforces 601C Kleofáš and the n-thlon 概率dp
Kleofáš and the n-thlon 我们可以用dp算出比当前这个人得分少的概率, 然后人数乘概率就好啦. dp[ i ][ j ]表示进行了 i 轮 得分为 j 的概率, 因为每个人都是独 ...
- Codeforces 280C Game on tree【概率DP】
Codeforces 280C Game on tree LINK 题目大意:给你一棵树,1号节点是根,每次等概率选择没有被染黑的一个节点染黑其所有子树中的节点,问染黑所有节点的期望次数 #inclu ...
- codeforces#1139D. Steps to One (概率dp+莫比乌斯反演)
题目链接: http://codeforces.com/contest/1139/problem/D 题意: 在$1$到$m$中选择一个数,加入到一个初始为空的序列中,当序列的$gcd$和为$1$时, ...
随机推荐
- Linux Shell管道调用用户定义函数(使shell支持map函数式特性)
Linux中有一个管道的概念,常用来流式的处理文本内容,比如一个文件对其中的每一行应用好几个操作,出于两个方面的考虑可能需要在管道中使用用户定义函数: 1. 刚需: 内置的sed/awk之类的可能没法 ...
- Python练习-基于socket的FTPServer
# 编辑者:闫龙 import socket,json,struct class MySocket: with open("FtpServiceConfig","r&qu ...
- [转]ubuntu16.04~qt 5.8无法输入中文
编译fcitx-qt需要cmake,安装cmake命令,如果已经安装,请略过. sudo apt-get install cmake 安装 fcitx-libs-dev sudo apt-get in ...
- SQL 注入,永不过时的黑客技术
SQL 注入,永不过时的黑客技术 TalkTalk的信息泄漏事件导致约15万人的敏感信息被暴露,涉嫌造成这一事件的其中一名黑客使用的并不是很新的技术.事实上,该技术的「年纪」比这名15岁黑客还要大两岁 ...
- mysql 增加字段脚本,以及删除主键约束的脚本,存储过程
//增加一个库下面所有表的row_id和其他9个字段的存过 DELIMITER $$ USE `erptest`$$ DROP PROCEDURE IF EXISTS `UPTABLE`$$ CREA ...
- Android Framebuffer介绍及使用【转】
转自:https://www.jianshu.com/p/df1213e5a0ed 来自: Android技术特工队 作者: Aaron 主页: http://www.wxtlife.com/ 原文连 ...
- Group Normalization笔记
作者:Yuxin,Wu Kaiming He 机构:Facebook AI Research (FAIR) 摘要:BN是深度学习发展中的一个里程碑技术,它使得各种网络得以训练.然而,在batch维度上 ...
- Linux压缩打包方法连载之三:bzip2, bzcat 命令
Linux压缩打包方法有多种,本文集中讲解了bzip2, bzcat 命令的使用.案例说明,例如# 与 gzip 同样的,都是在计算压缩比的参数,-9 最佳,-1 最快. AD: 我们遇见Linux压 ...
- 牛x的JavaScript编辑器你知道几个
英文:Martin Heller 译文:葡萄城控件 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入学习交流群343599877,我们一起学前端! 对于JavaScript程序员来说,目前有很 ...
- day06作业
一.方法 1.方法是完成特定功能的代码块. 修饰符 返回值类型 方法类型(参数类型 参数名1,参数类型 参数名2,...){ 方法体语句: return返回值: } 修饰符:目前就用publi ...