Codeforces 498B. Name that Tune

Source: Internet
Author: User

the topic is more difficult to understand, the main idea: to give you a N,M representative has n song, in m seconds to guess the song. Let you find out what the number of songs you can guess after M seconds is expected. Next n lines, each line has two digits the first PI represents the probability that you guessed before the end of the song, the second TI stands for this song up to play Ti seconds, after t seconds you can guess the percentage of the song. Last output m seconds after guessing the song's expectations.

We set DP[I][J] to enumerate to the first song, which takes exactly the desired time of J.

DP[I][J] can be transferred by state Dp[i-1][j-ti],dp[i-1][j-ti+1],......, dp[i-1][j-1].

DP[I][J] = dp[i-1][j-ti]* (1-pi) ^ (ti-1) +dp[i-1][j-ti+1]* (1-pi) ^ (ti-2) *p+dp[i-1][j-ti+2]* (1-pi) ^ (ti-3) *p+ ... +dp[i-1][j-1]*p

Note that Dp[i][j-ti] at this point I will be sure to guess the song. So dp[i][j] + = Dp[i-1][j-ti]*pow ((1-pi), TI);

There is to subtract the former useless state, dp[i-1][j-ti-1] state is not pushed to dp[i][j], so subtract.

Set ans= dp[i-1][j-ti+1]* (1-PI) ^ (ti-2) +dp[i-1][j-ti+2]* (1-pi) ^ (ti-3) +......+dp[i-1][j-1], so as long as j+1 (ans=ans*) is pushed from J to 1-pi +DP[I-1][J]

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

#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <ctime> #include <map> #include <set> #define EPS 1e-9///#define M 1000100///#define ll __int64#define ll Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((FA BS (x) <eps)? 0:x) #define MOD 1000000007#define Read () freopen ("Autocomplete.in", "R", stdin) #define Write () freopen ("    Autocomplete.out "," w ", stdout) #define CIN () Ios::sync_with_stdio (false) using namespace Std;inline int Read () {char ch;    BOOL flag = FALSE;    int a = 0; while (!) ( ((ch = getchar ()) >= ' 0 ') && (ch <= ' 9 ')) | |    (ch = = '-')));        if (ch! = '-') {a *= 10;    A + = ch-' 0 ';    } else {flag = true; } while (((ch = getchar ()) >= ' 0 ') && (ch <= ' 9 ')) {        A *= 10;    A + = ch-' 0 ';    } if (flag) {a = A; } return A;        void write (int a) {if (a < 0) {Putchar ('-');    A =-A;    } if (a >=) {write (A/10); } putchar (a% 10 + ' 0 ');}    const int MAXN = 5050;struct node{double p; int ti;}    F[MAXN];d ouble dp[maxn][maxn];int main () {int n, m; while (Cin >>n>>m) {for (int i = 1; I <= n; i++) {scanf ("%lf%d", &AMP;F[I].P,            &f[i].ti);        F[I].P/= 100.0;        } for (int i = 0; I <= m; i++) dp[0][i] = 0;        Dp[0][0] = 1;        Double sum = 0.0;            for (int i = 1; I <= n; i++) {double ans = 0;            Double q = Pow (1-F[I].P, 1.0*f[i].ti);                for (int j = 0; J <= M; j + +) {if (j-1 >= 0) ans + = dp[i-1][j-1];                if ((j-f[i].ti-1) >= 0) ans-= dp[i-1][j-f[i].ti-1]*q;                DP[I][J] = ANS*F[I].P; if (j-f[i].ti >= 0) dp[i][j] + + dp[i-1][j-f[i].ti]*q;                Ans *= (1.0-F[I].P);            Sum + = Dp[i][j];    }} printf ("%.10lf\n", sum); } return 0;}


Codeforces 498B. Name that Tune

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.