Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]
1 second
256 megabytes
standard input
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.
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 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.
2 2
50 2
10 1
1.500000000
2 2
0 2
100 2
1.000000000
3 3
50 3
50 2
25 2
1.687500000
2 2
0 2
0 2
1.000000000
感觉集齐了各种坑,萌萌哒~ 以后只能默默地给田神拎包了
| 9288439 | 2014-12-28 07:06:00 | njczy2010 | D - Name That Tune | GNU C++ | Accepted | 483 ms | 196200 KB |
| 9288416 | 2014-12-28 07:01:48 | njczy2010 | D - Name That Tune | GNU C++ | Runtime error on test 36 | 93 ms | 196100 KB |
| 9288373 | 2014-12-28 06:54:26 | njczy2010 | D - Name That Tune | GNU C++ | Runtime error on test 36 | 109 ms | 196100 KB |
| 9288341 | 2014-12-28 06:49:32 | njczy2010 | D - Name That Tune | GNU C++ | Runtime error on test 36 | 93 ms | 196200 KB |
| 9288329 | 2014-12-28 06:46:58 | njczy2010 | D - Name That Tune | GNU C++ | Runtime error on test 36 | 93 ms | 196100 KB |
| 9288318 | 2014-12-28 06:44:55 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 3 | 93 ms | 196100 KB |
| 9288297 | 2014-12-28 06:40:00 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 3 | 62 ms | 196100 KB |
| 9288283 | 2014-12-28 06:36:34 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 3 | 109 ms | 196100 KB |
| 9288245 | 2014-12-28 06:25:16 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 7 | 62 ms | 196200 KB |
| 9288232 | 2014-12-28 06:20:57 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 7 | 124 ms | 196100 KB |
| 9272178 | 2014-12-26 04:14:38 | njczy2010 | D - Name That Tune | GNU C++ | Time limit exceeded on test 13 | 1000 ms | 196200 KB |
| 9272163 | 2014-12-26 04:09:52 | njczy2010 | D - Name That Tune | GNU C++ | Time limit exceeded on test 13 | 1000 ms | 196200 KB |
| 9267879 | 2014-12-25 16:29:08 | njczy2010 | D - Name That Tune | GNU C++ | Wrong answer on test 6 | 62 ms | 196200 KB |
| 9267835 | 2014-12-25 16:25:22 | njczy2010 | D - Name That Tune | GNU C++ | Memory limit exceeded on test 1 | 108 ms | 262100 KB |
| 9267811 | 2014-12-25 16:23:15 | njczy2010 | D - Name That Tune | GNU C++ | Memory limit exceeded on test 1 | 93 ms | 262100 KB |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#define eps 1e-3
#define ll long long
#define N 5005
#define M 10005
#define mod 2007 using namespace std; int n,T;
double dp[N][N];
double ans;
double tot;
double p[N];
int t[N];
//double q[N][N]; void ini()
{
ans=;tot=;
T++;
memset(dp,,sizeof(dp));
// memset(q,0,sizeof(q));
int i;
for(i=;i<=n;i++){
scanf("%lf%d",&p[i],&t[i]);
p[i]/=;
}
dp[][]=1.0;
//for(i=1;i<=n;i++){
// q[i][1]=p[i];
// q[i][ t[i] ]=1;
// for(j=2;j<=t[i]-1;j++){
// q[i][j]=q[i][j-1]*(1.0-p[i]);
// }
// }
} void solve()
{
int i,j;
int tmin,tmax;
tmin=,tmax=;
//double tmp;
for(i=;i<=min(n,T);i++){
tmin++;tmax=min(T,tmax+t[i]);
// tmp=pow(1-p[i],t[i]-1);
for(j=tmin;j<min(tmax,tmin+t[i]-);j++){
dp[j][i]=dp[j-][i]*(-p[i])+dp[j-][i-]*p[i];
}
if(j<=tmax){
dp[j][i]=dp[j-][i]*(-p[i])+dp[j-][i-]*p[i]+dp[ j-t[i] ][i-]*pow(-p[i],t[i]);
j++;
}
if(i==) continue;
for(;j<=tmax;j++){
dp[j][i]=(dp[j-][i]-dp[ j-t[i]- ][i-]*pow(-p[i],t[i]-))
*(-p[i])+dp[j-][i-]*p[i]+dp[ j-t[i] ][i-]*pow(-p[i],t[i]);
}
}
} void out()
{
int i,j;
// for(j=1;j<=T;j++){
// for(i=1;i<=n;i++) printf(" j=%d i=%d dp=%.4f\n",j,i,dp[j][i]);
// }
for(j=;j<=T;j++){
for(i=;i<=n;i++){
tot+=dp[j][i];
}
}
//ans/=tot;
printf("%.8f\n",tot);
} int main()
{
//freopen("data.in","r",stdin);
// scanf("%d",&T);
//while(T--){
while(scanf("%d%d",&n,&T)!=EOF){
ini();
solve();
out();
}
return ;
}
Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]的更多相关文章
- Codeforces Round #301 (Div. 2) D. Bad Luck Island 概率DP
D. Bad Luck Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/pr ...
- Codeforces Round #284 (Div. 1) B. Name That Tune(概率DP)(难)
B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP
D. Painting The Wall ...
- Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp
E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
随机推荐
- OC 导入类 #import和@class 区别
objective-c中#import和@class的区别 在Objective-C中,可以使用#import和@class来引用别的类型, 但是你知道两者有什么区别吗? @class叫做forwar ...
- 利用VS自带的命令行工具查看和生产PublicKeyToken
使用VS2008(或其他版本)命令行工具,键入:SN -T C:\*****.dll 就会显示出该dll具体的PublicKeyToken数值. 如果该程序集没有强命 名,则不会有PublicKeyT ...
- C语言中最常用标准库函数
标准头文件包括: <asset.h> <ctype.h> <errno.h> <float.h> <limits ...
- 安装pycharm 2018.3 Professional Edition
1.下载pycharm 2018.3 Professional 2.下载破解补丁,Gitee仓库 或 直接下载(Direct download link) ,并放到pycharm目录下的\bin目录( ...
- 详解Mac睡眠模式设置
详解Mac睡眠模式设置 原文链接:http://www.insanelymac.com/forum/index.php?showtopic=281945 需要说明的是,首先这篇文章是针对已经能够成功睡 ...
- 洛谷 P2872 道路建设
https://www.luogu.org/problemnew/show/P2872 算是比较裸的并查集了,已经有路的两个点之间建一条代价为0的边,路径长度计算两点之间的距离,做并查集就好咯. #i ...
- 十:MYSQL中的事务
前言: 因为没有多少时间和精力,目前无法深入研究数据库中的事务,比如 但是,对于事务的一些基本知识,还是需要牢牢掌握的,做到了解事务的基本常识,在实际开发中能够理解各个持久层框架对事务的处理 一:是么 ...
- 继上次编译openwrt之后,添加web界面
上编博客写了关于openwrt编译环境和编译一个默认配置的openwrt系统. 现在我正在做如何添加web界面.(hiwooya自带的luci web) 方法如下: 首先在编译环境中配置 make m ...
- 绑定用户id,用户权限认证
上面这个就是为了把user_id与文章关联起来 文章需要跟用户关联,所以要去文章模型中加以关联 这样就可以直接在模板中进行关联处理 权限认证 首先要创建policy php artisan make: ...
- MySQL之单表查询、多表查询
一.单表查询: 单个表的查询方法及语法顺序需要通过实际例子来熟悉 先将表数据创建下: mysql> create database singe_t1; # 建个数据库singe_t1 Query ...