ccbeginner

UVa Q10081

Jan 2nd, 2020
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //UVa Q10081
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. double dp[101][12];
  6.  
  7. int main(){
  8.     int n,k;
  9.     while(cin >> k >> n){
  10.         ++k;
  11.         memset(dp, 0, sizeof(dp));
  12.         for(int i = 1; i <= k; ++i)dp[1][i] = 1;
  13.         for(int i = 2; i <= n; ++i){
  14.             for(int j = 1; j <= k; ++j){
  15.                 dp[i][j] = (dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1]) / k;
  16.             }
  17.         }
  18.         double sum = 0;
  19.         for(int i = 1; i <= k; ++i)sum += dp[n][i];
  20.         printf("%.5f\n", sum*100/k);
  21.     }
  22.     return 0;
  23. }
RAW Paste Data