Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <ctime>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <bitset>
- #include <queue>
- #include <complex>
- #include <cassert>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define fs first
- #define sc second
- #define sz(s) int((s).size())
- #define eprintf(...) fprintf(stderr, __VA_ARGS__)
- #define next _next
- #define prev _prev
- #define rank _rank
- typedef long long ll;
- typedef long long llong;
- typedef unsigned int uint;
- typedef unsigned long long ull;
- typedef vector <int> vi;
- typedef pair <int, int> pii;
- typedef complex <double> tc;
- const int inf = int(1e9);
- const double eps = 1e-9;
- const double pi = 4 * atan(double(1));
- long double d[555][555];
- int main(){
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- freopen("runs.in", "r", stdin);
- freopen("runs.out", "w", stdout);
- int n, k;
- scanf("%d %d", &n, &k);
- if(k >= n){
- printf("0\n");
- return 0;
- }
- for(int i = 1; i <= n; i++){
- for(int j = 0; j <= min(i - 1, k); j++){
- if(i == 1 && j == 0){
- d[i][j] = 1;
- }
- else{
- d[i][j] = (j * d[i - 1][j] + 2 * (j >= 1 ? d[i - 1][j - 1] : 0) + (i - j) * (j >= 2 ? d[i - 1][j - 2] : 0)) / i;
- }
- }
- }
- printf("%.9Lf\n", d[n][k]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement