Advertisement
Guest User

Untitled

a guest
Aug 31st, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1.     #define VERBOSE
  2.     #define _USE_MATH_DEFINES
  3.     #define _CRT_SECURE_NO_WARNINGS
  4.     #include <algorithm>
  5.     #include <fstream>
  6.     #include <bitset>
  7.     #include <cctype>
  8.     #include <cfloat>
  9.     #include <climits>
  10.     #include <cmath>
  11.     #include <cstdio>
  12.     #include <cstdlib>
  13.     #include <cstring>
  14.     #include <ctime>
  15.     #include <deque>
  16.     #include <functional>
  17.     #include <iomanip>
  18.     #include <iostream>
  19.     #include <list>
  20.     #include <map>
  21.     #include <numeric>
  22.     #include <queue>
  23.     #include <set>
  24.     #include <sstream>
  25.     #include <stack>
  26.     #include <string>
  27.     #include <vector>
  28.      
  29.     #ifndef _DEBUG
  30.     # undef VERBOSE
  31.     #endif
  32.     #ifdef NDEBUG
  33.     #define VERBOSE
  34.     #endif
  35.      
  36.     #define eps 1e-8
  37.     #define inf (1000 * 1000 * 1000)
  38.     #define linf (4LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000)
  39.     #define sqr(x) ((x) * (x))
  40.     #define eq(x, y) (((x) > (y) ? (x) - (y) : (y) - (x)) <= eps)
  41.     #define sz(x) int((x).size())
  42.     #define all(x) (x).begin(), (x).end()
  43.     #define rall(x) (x).rbegin(), (x).rend()
  44.     #define mp make_pair
  45.     #define FOR(i, n) for(int (i) = 0; (i) < (n); ++(i))
  46.     #define FORN(i, n) for(int (i) = 1; (i) <= (n); ++(i))
  47.     #define REP(i,from,to) for(int (i) = (from); (i) <= (to); ++(i))
  48.     #define RREP(i,from,to) for(int (i) = (from); (i) >= (to); --(i))
  49.     #define FOREACH(iter, cont) for(__typeof(cont)::iterator it = (cont).begin(); (it) != (cont).end(); ++(it))
  50.      
  51.      
  52.     using namespace std;
  53.      
  54.     typedef unsigned uint;
  55.     typedef long long llong;
  56.     typedef unsigned long long ullong;
  57.     typedef long double ldouble;
  58.     typedef vector<int> vi;
  59.     typedef vector<vi> vvi;
  60.     typedef vector<double> vd;
  61.     typedef vector<vd> vvd;
  62.     struct debug_t {
  63.       template <typename T>
  64.       debug_t& operator<<(const T& value) {
  65.     # ifdef VERBOSE
  66.         cout << value;
  67.     # endif
  68.         return *this;
  69.       }
  70.     } debug;  
  71.      
  72.     double dp[501][3001]; // dp[cnt][sum]
  73.     double rec(int cnt, int sum) {
  74.       if( sum < 0 ) return 0;
  75.       if( dp[cnt][sum] != -1 )
  76.         return dp[cnt][sum];
  77.       double result = 0;
  78.       FORN(a,6)
  79.         result += rec(cnt-1,sum-a)/6;
  80.       return dp[cnt][sum] = result;
  81.     }
  82.      
  83.     int main() {  
  84.       //freopen(TASK ".in", "r", stdin);
  85.       //freopen(TASK ".out", "w", stdout);
  86.       freopen("input.txt", "r", stdin);
  87.       //freopen("output.txt", "w", stdout);
  88.       //freopen("info.txt", "r", stdin);
  89.       //freopen("info.txt", "w", stdout);
  90.       ios_base::sync_with_stdio(false);
  91.       cin.tie(NULL);  
  92.      
  93.       int n,q; cout << setprecision(3) << fixed;
  94.       while( cin >> n >> q ) {    
  95.         FOR(i,501) FOR(j,3001) dp[i][j] = -1;
  96.         FOR(j,3001) dp[1][j] = dp[0][j] = 0;
  97.         FORN(j,6)
  98.           dp[1][j] = 1.0 / 6.0;
  99.         cout << rec(n,q) << "\n";
  100.       }
  101.      
  102.       return 0;
  103.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement