Codeforces 498B. Name that Tune probability dp+ optimization

Source: Internet
Author: User


DP[I][J] The first song in the J-minute sounds ...

Normally: dp[i][j]= dp[i-1] [j-k] * p[i] * (1-p[i]) ^ (k-1)

When K==t[i], must be able to hear the additional dp[i-1] [j-k]* (1-p[i]) ^k


Need to maintain a dp[i-1][k] and to reduce the time system to O (n^2)

B. Name that tunetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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.

TheI-th Song of Ac/pe have its recognizability Pi . This means so if the song has no yet been recognized by you, your listen to it for exactly one more second and with prob Ability of Pi Percent you recognize 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  i  seconds of 

For Example, in 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 Test (s) 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


/* ***********************************************author:ckbosscreated time:2015 March 20 Friday 14:25 28 seconds file Name : cf498b_2.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const    int maxn=5500;int n,t;double dp[maxn][maxn];int t[maxn];d ouble p[maxn];int Main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), scanf ("%d%d", &n,&t), for (int i=1;i<=n;i++) {scanf ("%lf%d", p+i,t+i); p[i ]/=100.;} dp[0][0]=1;double ans=0;for (int i=1;i<=n;i++) {double P=p[i],vp=1-p[i],vpn=pow (vp,t[i]);d ouble temp=0;for (int j=0 ; j<=t;j++) {if (j-1>=0) temp+=dp[i-1][j-1];if (j-t[i]-1>=0) temp-=dp[i-1][j-t[i]-1]*vpn;dp[i][j]+=temp*p; if (j-t[i]>=0) Dp[i][j]+=dp[i-1][j-t[i]]*vpn;temp=temp*vp;ans+=dP[I][J];}}        printf ("%.11lf\n", ans); return 0;}




Codeforces 498B. Name that Tune probability dp+ optimization

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.