【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$时, ...
随机推荐
- PHP编程效率的20个要点-[转]
用 单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符 串当作参数的“函数”(译注:PHP手 ...
- Unity3D 程序打包报错(程序是连接数据库进行处理的)
打包这个Unity3D的程序时出现错误(程序是由XML数据改成连接数据库): ArgumentException: The Assembly System.Configuration is refer ...
- 零值比较--BOOL,int,float,指针变量与零值比较的if语句
这是程序员面试的一道常见题,也是个C++基础问题.若只在大学里看过几本基础的编程入门书,看见这道题可能会觉得奇怪,不就是和0比较吗,直接拿出来比就是了,其实非也.下文引自google搜索结果,出处不详 ...
- 【内核】linux内核启动流程详细分析【转】
转自:http://www.cnblogs.com/lcw/p/3337937.html Linux内核启动流程 arch/arm/kernel/head-armv.S 该文件是内核最先执行的一个文件 ...
- HTTP之二 http 301 和 302的区别
1.什么是301转向?什么是301重定向? 301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种, ...
- 随机数生成 && 生成执行锁
生成随机数列: openssl rand -base64 uuidgen echo $RANDOM | md5sum echo $RANDOM | sha256sum 随机小写10个字母 随机数: [ ...
- 使用DOS访问数据库详解
今天突发奇想,想是否可以用DOS命令来操作本地数据库或者连接其他外地数据库,网上搜了很多教程比较繁琐,自己想写一篇文章详细叙述一下,也为以后复习做点备份. 工具: 电脑 win7 64bit MySQ ...
- 数据库-mysql数据库和表操作
一:数据库查询增加删除 1)mysql数据库查询:show databases MariaDB [mysql]> show databases; +--------------------+ | ...
- R语言以及RStdio的安装
R语言: 首先从官网上下载R安装包, 提供了Linux, (Mac) OS X, Windows的安装包相关下载链接. RStdio: RStdio(官网)是R言语非常实用的IDE, 是一个免费的软件 ...
- 耗时任务DefaultEventExecutorGroup 定时任务
一. 耗时任务 static final EventExecutorGroup group = new DefaultEventExecutorGroup(16); // Tell the pipel ...