solution
d p [ i + 1 ] [ j ] = d p [ i ] [ j ] + d p [ i ] [ j + 1 ] + d p [ i ] [ j − 1 ] dp[i+1][j]=dp[i][j]+dp[i][j+1]+dp[i][j-1] dp[i+1][j]=dp[i][j]+dp[i][j+1]+dp[i][j−1]
a n s w e r = ∑ i = 0 k d p [ n ] [ i ] ( k + 1 ) n answer=\frac{\sum\limits_{i=0}^{k}dp[n][i]}{(k+1)^n} answer=(k+1)ni=0∑kdp[n][i]
code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, _k;
double dp[110][10];
void solve() {
while (cin >> _k >> n) {
double res = 0;
memset(dp, 0, sizeof dp);
for (int i = 0; i <= _k; ++i) dp[1][i] = 1;
for (int i = 1; i < n; ++i) {
for (int j = 0; j <= _k; ++j) {
dp[i + 1][j] += dp[i][j];
if (j != 0) dp[i + 1][j] += dp[i][j - 1];
if (j != _k) dp[i + 1][j] += dp[i][j + 1];
}
}
for (int i = 0; i <= _k; ++i) res += dp[n][i];
for (int i = 1; i <= n; ++i) res /= _k + 1;
cout << fixed << setprecision(5) << res * 100 << endl;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
return 0;
}