Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- #define pii pair<int,int>
- #define pll pair<LL,LL>
- #define vi vector<int>
- #define SYNC ios_base::sync_with_stdio(0)
- #define CT cin.tie(0)
- #define sf(a) scanf("%d", &a)
- #define sff(a, b) scanf("%d %d", &a, &b)
- #define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
- #define debug printf("Here\n")
- #define PI acos(-1)
- #define all(x) (x.begin(),x.end())
- #define mem(x, val) memset((x),val,sizeof((x)))
- #define xx first
- #define yy second
- #define pb push_back
- #define _max(a,b,c) max(a, max(b, c))
- #define _min(a,b,c) min(a, min(b, c))
- #define INF INT_MAX
- #define MOD 1000000007
- #define NN 1005
- int setBit(int n, int pos) { return n = n | (1 << pos); }
- int resetBit(int n, int pos) { return n = n & ~(1 << pos); }
- bool checkBit(int n, int pos) { return (bool)(n & (1 << pos)); }
- double dp[NN][NN];
- double call(int n, int m, int tot) {
- if(n == 0) return 1;
- if(m == 0 && n == 1) return 0;
- if(dp[n][m] != -1) return dp[n][m];
- double ret = 0;
- if(m) ret += ((double) n / (double)tot) * ((double)m / ((double)tot - 1.0)) * call(n, m - 1, tot - 1);
- if(n > 1) ret += ((double) n / (double)tot) * ((double)n - 1.0) / ((double)tot - 1.0) * call(n - 2, m, tot - 2);
- return dp[n][m] = ret;
- }
- int main() {
- for(int i = 0; i < NN; i++)
- for(int j = 0; j < NN; j++)
- dp[i][j] = -1;
- int t, d, T, tt = 1;
- sf(T);
- while(T--) {
- sff(t, d);
- printf("Case %d: %.10lf\n", tt++, call(t, d, t + d + 1));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment