Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Tittle: 10081 - Tight Words
- * Author: Cheng-Shih, Wong
- * Date: 2015/03/18
- */
- // include files
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- // definitions
- #define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
- #define clr(x,v) memset( x, v, sizeof(x) )
- #define cur(x) ((x)&1)
- #define pre(x) (((x)-1)&1)
- // declarations
- double dp[2][10];
- // functions
- int k, n;
- double ans;
- // main function
- int main( void )
- {
- double d;
- // input
- while( scanf( "%d%d", &k, &n )==2 ) {
- // solve
- clr( dp, 0 );
- d = k+1.0;
- FOR( i, 0, k ) dp[0][i] = 1/d;
- FOR( i, 1, n-1 ) {
- clr( dp[cur(i)], 0 );
- FOR( j, 0, k ) {
- if( j > 0 ) dp[cur(i)][j] += dp[pre(i)][j-1];
- dp[cur(i)][j] += dp[pre(i)][j];
- if( j < k ) dp[cur(i)][j] += dp[pre(i)][j+1];
- dp[cur(i)][j] *= 1/d;
- }
- }
- ans = 0;
- FOR( i, 0, k ) ans += dp[cur(n-1)][i];
- // output
- printf( "%.5lf\n", ans*100 );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement