Codeforces Name that Tune (probability DP)

Source: Internet
Author: User

Test instructionsD-Name that TuneTime limit:MS Memory Limit:262144KB 64bit IO Format:%i64d &%i64u SubmitStatusPracticecodeforces 499DAppoint Description:System Crawler (2015-01-05)

Description

It turns is 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, a nd you has to find out the name of the song. After your tell the song name, Peter immediately plays the following song in order, and so on.

The  i -th Song of Ac/pe have its Recognizability  p i . This means so if the song has not yet been recognized by you, you list En to it for exactly one more second and with probability Of  p i  percent You recognize it and tell it ' s name. Otherwise you continue listening it. Note that you can have only try to guess it if it is an integer number of seconds after the moment the song starts playing.

In all Ac/pe songs the first words of chorus is 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 it name for sure.

For example, the song Highway to Red the chorus sounds pretty late, but the song had 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 h ARD 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 would recognize if the game lasts for exactly T seconds (I. E. You can Make the last guess of the second T, after the game stops).

If All songs be recognized faster than in T seconds, the game stops after the last song is recognized.

Input

The first line of the input contains numbersNandT(1?≤? n? ≤?5000,1?≤? T? ≤?5000), separated by a space. NextNLines contain pairs of numbers Pi and Ti (0?≤? P i? ≤?100 ,1?≤? T i? ≤? T ). The songs is given in the same order as in Petya ' s list.

Output

Output A single number-the expected number of the number of songs you'll recognize in T seconds. Your answer would be considered correct if it absolute or relative error does not exceed ?-? 6.

Sample Input

Input
2 250 210 1
Output
1.500000000
Input
2 20 2100 2
Output
1.000000000
Input
3 350 350) 225 2
Output
1.687500000
Input
2 20 20 2
Output
1.000000000
Analysis: We can define DP[I][J] to indicate that the first song is guessed at the time of J second, then when the first song is guessed, the former I-1 song is also guessed, and the state transfer takes place between the first and the first layers of the i-1;
PS: The final expectation is equal to the probability of each layer of the sum, this is because guessing the expectations of the song is equal to each of the songs are guessed the expectation and;
#include <iostream> #include <stdio.h> #include <string> #include <string.h> #include < Cstdio> #include <algorithm>using namespace std;double p[5500],dp[5500][5500];int t[5500],n,t;double Pow (  Double P,int t) {double Ans=1;  for (int i=1;i<=t;i++) ans*=p; return ans;}  void DP () {dp[0][0]=1.0;  Double ans=0.0;        for (int i=1;i<=n;i++) {double f=0.0;        Double Tt=pow (1-p[i], t[i]-1);           for (int j=i;j<=t;j++) {f=f* (1-p[i]) +dp[i-1][j-1];             if (J>=t[i]) {f=f-dp[i-1][j-t[i]]*tt;           Dp[i][j]=f*p[i]+dp[i-1][j-t[i]]*tt;           } else dp[i][j]=f*p[i];         ANS+=DP[I][J]; }} printf ("%.9lf\n", ans);}     int main () {while (scanf ("%d%d", &n,&t)!=eof) {memset (dp,0,sizeof (DP));        for (int i=1;i<=n;i++) {scanf ("%lf%d", &p[i],&t[i]);     p[i]/=100;  } DP (); } return 0;}

Codeforces Name that Tune (probability DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.