Acdream 1113 The Arrow (probability dp)
Question:
The initial state is 0. Each time a dice is dropped [], if it is in x, the number of dice is y, and if x + y> n, it is still in x.
Calculate the expected number of times the dice are dropped from 0 to n.
Analysis:
This is changed from the previous one: if the number of dice is y in x, and if the number of dice is y in x + y> n, the number of dice remains in x.
Then we set dp [I] to indicate the expected number of dice to be dropped from I to n.
So
We set the possibility to stay in the same place every time x times.
Dp [I] = dp [I] * y/6 + dp [I + 1]/6 + dp [I + 2]/6... + 1;
Then the formula of dp [I] is simplified.
The Code is as follows:
#include
#include
#include
#include using namespace std;const int maxn = 1e5+10;double dp[maxn];int main(){ int t,n; scanf(%d,&t); while(t--){ scanf(%d,&n); memset(dp,0,sizeof(dp)); for(int i=n-1;i>=0;i--){ int tot=0; double tmp=0; for(int j=1;j<=6;j++){ if(i+j>n) tot++; else tmp+=dp[i+j]/6.0; } //cout<