10081-tight Words
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_ problem&problem=1022
Train of thought: a string of length I, if the end number is J, then the number of such strings must be long as i-1 string, the mantissa is j-1,j,j+1 the sum of the number of three kinds of cases (within the boundary)
Complete code:
/*0.019s*/
#include <bits/stdc++.h>
using namespace std;
Double dp[111][11];
int main ()
{
int k, n, I, J;
Double ans;
while (~SCANF ("%d%d", &k, &n))
{for
(i = 0; I <= k; ++i) dp[1][i] = 1.0/(k + 1);
for (i = 2; I <= n; ++i) for
(j = 0; j <= K; ++j)
{
dp[i][j] = Dp[i-1][j]/(k + 1);
if (J > 0) dp[i][j] + = Dp[i-1][j-1]/(k + 1);
if (J < K) Dp[i][j] + = dp[i-1][j + 1]/(k + 1);
}
Ans = 0;
for (i = 0; I <= K; i++) ans + = dp[n][i];
printf ("%.5f\n", ans *);
return 0;
}
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/