Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <queue>
- #include <map>
- #include <set>
- #include <cmath>
- #include <sstream>
- #include <stack>
- #include <cassert>
- #define pb push_back
- #define mp make_pair
- #define PI 3.1415926535897932384626433832795
- #define sqr(x) (x)*(x)
- #define forn(i, n) for(int i = 0; i < n; ++i)
- #define ALL(x) x.begin(), x.end()
- #define F first
- #define S second
- #define m0(x) memset(x,0,sizeof(x))
- #define CC(x) cout << (x) << "\n"
- #define pw(x) (1ull<<(x)).
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- typedef pair<int,int> pii;
- const int INF = 2147483647;
- const ll LLINF = 9223372036854775807LL;
- ld d[550][550];
- int main() {
- freopen("runs.in", "r", stdin);
- freopen("runs.out", "w", stdout);
- int n,r;
- cin >> n >> r;
- forn(i,550) forn(k,550) d[i][k]=0;
- d[1][1]=1;
- d[2][1]=1;
- for(int i=3; i<=n; i++) {
- for(int k=1; k<i; k++) {
- ld ch0 = d[i-1][k]*k;
- ld ch1=0, ch2=0;
- if (k>=2) ch1=d[i-1][k-1]*2;
- if (k>=3) ch2=d[i-1][k-2]*(i-k);
- if (ch2<0) ch2=0;
- d[i][k]=(ch0+ch1+ch2)/i;
- }
- }
- double ans = d[n][r];
- printf("%0.11lf\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment