1570. Hopeless Coach
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
One of the Premier League (Persian Gulf Cup) teams had very bad results this year. The board is under pressure to fire the coach, but the coach is considered hero by some fans and it is not easy to fire him. The board decides to give him a last chance; they talked to media that they can only support the coach if the team gets at least 11 points in the next 5 matches. The coach wants to know the probability of passing their condition and ask you to help him. You can assume that the probability of having a win/draw/loss in a future match can be determined from the results of the matches the team currently has played. For example, if the team has already played 10 matches and has won three of them, the probability of having a win in any of the next five matches is 30%. The same rule applies to draws or losses.
You also know the team results (a win earns 3 points and a draw earns 1). There are 18 teams in the league and each team play against each of the other teams twice.
Input
There are multiple test cases in the input. The first line of each test case contains two numbers N and P. N is the number of matches and P is the points that are required in the next N games. This is followed by three numbers W, D and L (the number of wins, draws and losses in the previous games). The last line of the input contains two zero numbers.
Output
For each test case, you should print the percentage probability of getting at least P points in the next N matches with exactly one digit after decimal point.
Sample Input
5 11 3 5 4 2 3 5 0 5 3 5 5 5 4 1 1 1 1 1 0 0
Sample Output
4.3 75.0 42.866.7
// Problem#: 1570 // Submission#: 3322380 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ // All Copyright reserved by Informatic Lab of Sun Yat-sen University #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <string.h> #include <vector> #include <iomanip> #include <map> #include <stack> #include <functional> #include <list> #include <cmath> using namespace std; int main() { //std::ios::sync_with_stdio(false); while (1) { int N, P, W, D, L; scanf("%d%d", &N, &P); if (N == 0 && P == 0) break; scanf("%d%d%d", &W, &D, &L); double w = W * 1.0 / (W + D + L), d = D * 1.0 / (W + D + L), l = L * 1.0 / (W + D + L); vector<vector<double> > dp; dp.resize(N + 5); for (int i = 0; i < dp.size(); i++) dp[i].resize(3 * N + 3); dp[1][3] = w, dp[1][1] = d, dp[1][0] = l; for (int i = 2; i <= N; i++) { for (int j = 0; j <= 3 * i; j++) { if (j >= 3) dp[i][j] = dp[i - 1][j - 3] * w + dp[i - 1][j - 1] * d + dp[i - 1][j] * l; else if (j > 0) dp[i][j] = dp[i - 1][j - 1] * d + dp[i - 1][j] * l; else dp[i][j] = dp[i - 1][j] * l; } } double ans = 0; for (int i = P; i <= 3 * N; i++) ans += dp[N][i]; printf("%.1lf\n", 100 * ans); } //getchar(); //getchar(); return 0; }