Guest User

Untitled

a guest
Feb 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. const int N = 100;
  7. double dp[101][101][2];
  8. bool used[101][101][2];
  9.  
  10. double rec(int pos, int cont, int is_front){
  11. if(used[pos][cont][is_front]) return dp[pos][cont][is_front];
  12. double res = 0;
  13. if(pos == N) res = 1;
  14. else{
  15. // front
  16. for(bool next_is_front : {true, false}){
  17. if(next_is_front ^ is_front){
  18. res += 0.5 * rec(pos + 1, 1, next_is_front);
  19. }
  20. else{
  21. if(cont + 1 < 10)
  22. res += 0.5 * rec(pos + 1, cont + 1, next_is_front);
  23. }
  24. }
  25. }
  26. used[pos][cont][is_front] = true;
  27. return dp[pos][cont][is_front] = res;
  28. }
  29.  
  30. int main(){
  31.  
  32. cout << 1 - rec(0, 0, 0) << endl;
  33.  
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment