acdreamoj1117The Arrow 概率dp

扔筛子, 给定数n , 

He will write down a number N in the paper at first, and then throw the dice. When the sum of the number he throwed is less than N, he will keep throwing. But if the sum exceeds N, this throwing does not count.

For example, If the sum is 5,and N is 6, if we throw 2, 5 + 2 > 6, then  the sum keeps to be 5.

dp[i] = dp[i + 1] / 6 + … dp[i + 6] / 6 + 1 ;

但是最后六个数的概率要小心,比如

dp[n - 3] = dp[n - 3] / 2 + dp[n - 2] / 6 + dp[n - 1] / 6 + dp[n] / 6 + 1;

解一下方程


const int  maxn = 100008 ;
double  dp[maxn]  ;

int  main(){
     int t , n , i , j  , c ;
     cin>>t ;
     while(t--){
          scanf("%d" , &n) ;
          dp[n] = 0 ;
          for(i = n-1 ; i >= 0 ; i--){
               dp[i] = 6.0 ; c = 0 ;
               for(j = 1 ; j <= 6 ; j++){
                    if(i+j <= n) dp[i] += dp[i+j] ;
                    else  c++ ;
               }
               dp[i] /= (6-c) ;
          }
          printf("%.2lf\n" , dp[0]) ;
     }
     return 0 ;
}


你可能感兴趣的:(acdreamoj1117The Arrow 概率dp)