Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- int n;
- double p;
- double mem[26][26];
- double solve(int a, int b) {
- if(a == n) {
- return 1;
- }
- if(b == n) {
- return 0;
- }
- if(mem[a][b] != -1) {
- return mem[a][b];
- }
- double &ret = mem[a][b];
- ret = p*solve(a+1,b) + (1-p)*solve(a,b+1);
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- cout.precision(2);
- cout << fixed;
- int t;
- cin >> t;
- while(t--) {
- for(int i = 0; i < 26; i++) {
- for(int j = 0; j < 26; j++) {
- mem[i][j] = -1;
- }
- }
- cin >> n >> p;
- cout << solve(0,0) << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement