• 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 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 
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<algorithm>
     6 #include<map>
     7 #include<string>
     8 #include<vector>
     9 #include<queue>
    10 #include<cmath>
    11 #define eps 1e-3
    12 #define ll long long
    13 #define N 5005
    14 #define M 10005
    15 #define mod 2007
    16 
    17 using namespace std;
    18 
    19 int n,T;
    20 double dp[N][N];
    21 double ans;
    22 double tot;
    23 double p[N];
    24 int t[N];
    25 //double q[N][N];
    26 
    27 void ini()
    28 {
    29     ans=0;tot=0;
    30     T++;
    31     memset(dp,0,sizeof(dp));
    32 //    memset(q,0,sizeof(q));
    33     int i;
    34     for(i=1;i<=n;i++){
    35         scanf("%lf%d",&p[i],&t[i]);
    36         p[i]/=100;
    37     }
    38     dp[1][0]=1.0;
    39     //for(i=1;i<=n;i++){
    40     //    q[i][1]=p[i];
    41      //   q[i][ t[i] ]=1;
    42       //  for(j=2;j<=t[i]-1;j++){
    43       //      q[i][j]=q[i][j-1]*(1.0-p[i]);
    44        // }
    45    // }
    46 }
    47 
    48 void solve()
    49 {
    50     int i,j;
    51     int tmin,tmax;
    52     tmin=1,tmax=1;
    53     //double tmp;
    54     for(i=1;i<=min(n,T);i++){
    55         tmin++;tmax=min(T,tmax+t[i]);
    56        // tmp=pow(1-p[i],t[i]-1);
    57         for(j=tmin;j<min(tmax,tmin+t[i]-1);j++){
    58             dp[j][i]=dp[j-1][i]*(1-p[i])+dp[j-1][i-1]*p[i];
    59         }
    60         if(j<=tmax){
    61             dp[j][i]=dp[j-1][i]*(1-p[i])+dp[j-1][i-1]*p[i]+dp[ j-t[i] ][i-1]*pow(1-p[i],t[i]);
    62             j++;
    63         }
    64         if(i==1) continue;
    65         for(;j<=tmax;j++){
    66             dp[j][i]=(dp[j-1][i]-dp[ j-t[i]-1 ][i-1]*pow(1-p[i],t[i]-1))
    67             *(1-p[i])+dp[j-1][i-1]*p[i]+dp[ j-t[i] ][i-1]*pow(1-p[i],t[i]);
    68         }
    69     }
    70 }
    71 
    72 void out()
    73 {
    74     int i,j;
    75    // for(j=1;j<=T;j++){
    76    //     for(i=1;i<=n;i++) printf(" j=%d i=%d dp=%.4f
    ",j,i,dp[j][i]);
    77    // }
    78     for(j=2;j<=T;j++){
    79         for(i=1;i<=n;i++){
    80             tot+=dp[j][i];
    81         }
    82     }
    83     //ans/=tot;
    84     printf("%.8f
    ",tot);
    85 }
    86 
    87 int main()
    88 {
    89     //freopen("data.in","r",stdin);
    90    // scanf("%d",&T);
    91     //while(T--){
    92     while(scanf("%d%d",&n,&T)!=EOF){
    93         ini();
    94         solve();
    95         out();
    96     }
    97     return 0;
    98 }
  • 相关阅读:
    关于wangEditor粘贴图片自动上传
    关于xheditor粘贴图片自动上传
    SAS如何看待大数据
    SAS如何看待大数据
    大数据时代的电子商务​_数据分析师
    大数据时代的电子商务​_数据分析师
    Python 微信公众号文章爬取
    leetcode_445. 两数相加 II
    手把手教你用Gurobi求解一个数学模型
    Python 微信公众号文章爬取
  • 原文地址:https://www.cnblogs.com/njczy2010/p/4189806.html
Copyright © 2020-2023  润新知