D. 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.

Sample test(s)
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

感觉集齐了各种坑,萌萌哒~ 以后只能默默地给田神拎包了

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]的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

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

  5. Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                                   D. Painting The Wall ...

  6. 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 ...

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

  8. 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 ...

  9. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

随机推荐

  1. java读取clob字段的几种方法(转)

    http://blog.csdn.net/tanksyg/article/details/49927897 第一种 Clob clob = rs.getClob("remark") ...

  2. UVA - 12264 Risk (二分,网络流)

    题意比较坑,移动完以后的士兵不能再次移动,不然样例都过不了... 最小值最大满足决策单调性所以二分答案,跑网络流验证是否可行. 这种题重点在建图,为了保证只移动一次,拆点,一个入点一个出点,到了出点的 ...

  3. 在Solr中配置中文分词IKAnalyzer

    李克华 云计算高级群: 292870151 交流:Hadoop.NoSQL.分布式.lucene.solr.nutch 在Solr中配置中文分词IKAnalyzer 1.在配置文件schema.xml ...

  4. 按Esc键实现关闭窗体

    实现效果: 知识运用: KeyEventArgs类的KeyData属性 //获取KeyDown或KeyUp事件的键数据 public Keys KeyData {get;} 实现代码: private ...

  5. C03 程序逻辑

    程序逻辑 运算符 顺序结构 选择结构 循环结构 运算符 赋值运算符:= 比较运算符:>.<.==. >=.<=.!= 逻辑运算符:&&.||.! 顺序结构 在C ...

  6. Mac 下 Android Studio 安装

    给大家介绍下 Mac Os 系统下的 Android Studio 的安装吧,二者步骤类似. 方法/步骤   1 首先下载 Mac 环境下的 Android Studio 的安装包,为 dmg 格式的 ...

  7. TCP/IP各种数据包结构体

    下面这些TCP/IP数据包是我在进行Socket及Wipcap网络编程过程中曾经用到过的数据包结构体, 这些东西平时看起来不起眼,真正用到的时候就会觉得非常有用...... 以太帧头格式结构体,共14 ...

  8. 优化mysql查询

    mysql提供了一个特别的explain语句,用来分析查询语句的性能 : explain select ... 1.在所有用于where,order by,group by的列上添加索引 创建索引 添 ...

  9. 五:SQL语句中的数据类型

    一:MySQL数据类型 MySQL中定义数据字段的类型对你数据库的优化是非常重要的 MySQL支持多种数据类型,大致可以分为三类:数值 日期/时间和字符串 二.数值类型(12) 2.1.整数类型(6) ...

  10. sql 表连接的3种类型

    内连接  inner join (join) 交叉连接  cross join  笛卡尔积 效率低 外连接  outer join  (left join ,right join ,full join ...