标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2327 Accepted Submission(s): 1512
1 #include<cstdio> 2 #include<cstring> 3 4 using namespace std; 5 6 const int MAXN=1e5+10; 7 const int MAXM=1e3+10; 8 const double base=1.0/6.0; 9 10 double dp[MAXN]; 11 int jump[MAXN]; 12 13 double con(int x) 14 { 15 double res=0.0; 16 for(int i=x;i<=x+5;i++) 17 res+=dp[i]; 18 return res; 19 } 20 21 int main() 22 { 23 int n,m; 24 while(scanf("%d%d",&n,&m)) 25 { 26 if(!n&&!m) 27 break; 28 memset(jump,0,sizeof(jump)); 29 for(int i=0;i<m;i++) 30 { 31 int u,v; 32 scanf("%d%d",&u,&v); 33 jump[u]=v; 34 } 35 memset(dp,0,sizeof dp); 36 for(int i=n-1;i>=0;i--) 37 { 38 if(jump[i]) 39 dp[i]=dp[jump[i]]; 40 else 41 dp[i]=base*con(i+1)+1; 42 } 43 printf("%.4f\n",dp[0]); 44 } 45 return 0; 46 }
HDU 4405 Aeroplane chess 概率DP 水题
标签:
原文地址:http://www.cnblogs.com/-maybe/p/4677846.html