【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$时, ...
随机推荐
- VC++的全局变量(转)
全局变量一般这样定义:1.在一类的.cpp中定义 int myInt;然后再在要用到的地方的.cpp里extern int myInt:这样就可以用了. 2.在stdafx.cpp中加入:int my ...
- 《区块链100问》第81集:应用类项目Augur
Augur是基于以太坊区块链打造的去中心化预测平台,于2015年6月正式发布,是以太坊上的第一款应用. Augur采用了一个叫“群体智慧”的概念,它的意思是,一群人的智慧会高于这群人中最聪明的人.所以 ...
- ROS多线程订阅消息
对于一些只订阅一个话题的简单节点来说,我们使用ros::spin()进入接收循环,每当有订阅的话题发布时,进入回调函数接收和处理消息数据.但是更多的时候,一个节点往往要接收和处理不同来源的数据,并且这 ...
- Vue 项目添加 promise polyfill
1. 安装依赖 npm install es6-promise --save 2. 在 main.js 上面引入: import 'es6-promise/auto'
- linux 配置免密码登陆
在使用scp命令传输的时候需要密码 配置免密码登陆 ssh-keygen -t rsa (四个回车) 执行命令完成后,会生成两个文件id_rsa(私钥).id-rsa.pub(公钥) 将公钥拷贝到要免 ...
- 2017-2018-2 20179205《网络攻防技术与实践》Windows攻击实验
Windows攻击实验 实验描述: 使用Metaspoit攻击MS08-067,提交正确得到远程shell过程的截图(不少于五张). MS08-067漏洞介绍 MS08-067漏洞的全称为&quo ...
- input 标签禁止输入
1.鼠标可以点击输入框,但是不能输入 readonly 例如: <input class="layui-input" readonly > 2.鼠标点击输入框出现禁用图 ...
- Flask:使用Eclipse+PyDev插件编辑基于package的项目
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2,Eclipse Oxygen.1a Release (4.7.1a),PyDev 6.3.2 本文记录了 使用Ecli ...
- kafka集群及监控部署
1. kafka的定义 kafka是一个分布式消息系统,由linkedin使用scala编写,用作LinkedIn的活动流(Activity Stream)和运营数据处理管道(Pipeline)的基础 ...
- 原生JS实现AJAX、JSONP及DOM加载完成事件
一.JS原生Ajax ajax:一种请求数据的方式,不需要刷新整个页面:ajax的技术核心是 XMLHttpRequest 对象:ajax 请求过程:创建 XMLHttpRequest 对象.连接服务 ...