makrusak

Runs

Sep 30th, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <queue>
  7. #include <map>
  8. #include <set>
  9. #include <cmath>
  10. #include <sstream>
  11. #include <stack>
  12. #include <cassert>
  13.  
  14. #define pb push_back
  15. #define mp make_pair
  16. #define PI 3.1415926535897932384626433832795
  17. #define sqr(x) (x)*(x)
  18. #define forn(i, n) for(int i = 0; i < n; ++i)
  19. #define ALL(x) x.begin(), x.end()
  20. #define F first
  21. #define S second
  22. #define m0(x) memset(x,0,sizeof(x))
  23. #define CC(x) cout << (x) << "\n"
  24. #define pw(x) (1ull<<(x)).
  25.  
  26. using namespace std;
  27. typedef long long ll;
  28. typedef unsigned long long ull;
  29. typedef long double ld;
  30. typedef pair<int,int> pii;
  31. const int INF = 2147483647;
  32. const ll LLINF = 9223372036854775807LL;
  33.  
  34. ld d[550][550];
  35.  
  36. int main() {
  37.   freopen("runs.in", "r", stdin);
  38.   freopen("runs.out", "w", stdout);
  39.  
  40.   int n,r;
  41.   cin >> n >> r;
  42.   forn(i,550) forn(k,550) d[i][k]=0;
  43.   d[1][1]=1;
  44.   d[2][1]=1;
  45.   for(int i=3; i<=n; i++) {
  46.     for(int k=1; k<i; k++) {
  47.       ld ch0 = d[i-1][k]*k;
  48.       ld ch1=0, ch2=0;
  49.       if (k>=2) ch1=d[i-1][k-1]*2;
  50.       if (k>=3) ch2=d[i-1][k-2]*(i-k);
  51.       if (ch2<0) ch2=0;
  52.       d[i][k]=(ch0+ch1+ch2)/i;
  53.     }
  54.   }
  55.   double ans = d[n][r];
  56.   printf("%0.11lf\n", ans);
  57.   return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment