zoj2271 Chance to Encounter a Girl(DP)
生活随笔
收集整理的這篇文章主要介紹了
zoj2271 Chance to Encounter a Girl(DP)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*
?概率計算:按時間為階段,每個點由上一階段周圍的四個點來維護。
?注意事項:1.時間O(N^3*T),在問題的邊緣時間,所以打表計算。
???? 2.關于概率的求解,如果遇到就結束了,所以向后走就說明
?????? 之前沒有碰到,所以不用前面的碰到的概率計算后面的值。
*/
2 #include <string.h>
3
4 double answ[ 51 ] = {
5 0.0000,0.6667,0.0000,0.4074,0.0000,
6 0.3361,0.0000,0.2928,0.0000,0.2629,
7 0.0000,0.2407,0.0000,0.2233,0.0000,
8 0.2092,0.0000,0.1975,0.0000,0.1875,
9 0.0000,0.1789,0.0000,0.1714,0.0000,
10 0.1648,0.0000,0.1589,0.0000,0.1536,
11 0.0000,0.1487,0.0000,0.1443,0.0000,
12 0.1403,0.0000,0.1366,0.0000,0.1332,
13 0.0000,0.1300,0.0000,0.1270,0.0000,
14 0.1243,0.0000,0.1217,0.0000,0.1192};
15
16 /*
17
18 double maps[ 100 ][ 100 ][ 100 ];
19 short dxdy[ 4 ][ 2 ] = {1,0,0,1,-1,0,0,-1};
20
21 void madelist() // 打表程序
22 {
23 for ( int n = 1 ; n < 100 ; n += 2 ) {
24 double sum = 0.0;
25 memset( maps, 0, sizeof( maps ) );
26 maps[ 0 ][ n/2 ][ n/2 ] = 1.0;
27 for ( int t = 0 ; t < n ; ++ t )
28 for ( int i = 0 ; i < n ; ++ i )
29 for ( int j = 0 ; j < n ; ++ j )
30 for ( int k = 0 ; k < 4 ; ++ k ) {
31 int x = i+dxdy[ k ][ 0 ];
32 int y = j+dxdy[ k ][ 1 ];
33 if ( x > 0 && x < n-1 && y > 0 && y < n-1 )
34 maps[ t+1 ][ i ][ j ] += 0.25*maps[ t ][ x ][ y ];
35 else if ( ( x == 0 && y == 0 ) || ( x == 0 && y == n-1 ) ||
36 ( x== n-1 && y == 0 ) || ( x == n-1 && y == n-1 ) )
37 maps[ t+1 ][ i ][ j ] += 0.5*maps[ t ][ x ][ y ];
38 else maps[ t+1 ][ i ][ j ] += 1.0/3*maps[ t ][ x ][ y ];
39 if ( i == n/2 && j == t ) {
40 sum += maps[ t+1 ][ i ][ j ];
41 maps[ t+1 ][ i ][ j ] = 0.0;
42 }
43 }
44 printf("%.4lf,",sum);
45 }
46 }
47 */
48
49 int main()
50 {
51 int m;
52 while ( ~scanf("%d",&m) )
53 printf("%.4lf\n",answ[ m/2 ]);
54 return 0;
55 }
轉載于:https://www.cnblogs.com/-xiaobai-/archive/2011/08/18/2144243.html
總結
以上是生活随笔為你收集整理的zoj2271 Chance to Encounter a Girl(DP)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU_1541 Stars(树状数组)
- 下一篇: hdu 1671