Training Guide P327
Test instructions: 36 cards divided into 9 piles, 4 cards per heap. Take a couple of top cards at a time, but you need the same number of points. If there are a number of random laws such as probability of taking. If the final take all the cards then the game succeeds, the probability of success.
Open a 9-D array representing the state of each heap, simulating a search
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 Const intMax =6;7 CharS[max][max];8 inta[Ten][max *Max];9 intVis[max][max][max][max][max][max][max][max][max];Ten DoubleD[max][max][max][max][max][max][max][max][max]; One DoubleDfsintS1,intS2,intS3,intS4,intS5,intS6,intS7,intS8,intS9) A { - if(Vis[s1][s2][s3][s4][s5][s6][s7][s8][s9]) - returnD[S1][S2][S3][S4][S5][S6][S7][S8][S9]; theVIS[S1][S2][S3][S4][S5][S6][S7][S8][S9] =1; - intt[Ten] = {0, S1, S2, S3, S4, S5, S6, S7, S8, S9}; - BOOLFlag =true; - for(inti =1; I <=9; i++) + { - if(T[i]) + { AFlag =false; at Break; - } -}//if it's all 0, that means it's over, and this state is 1 . - if(flag) - { - returnD[S1][S2][S3][S4][S5][S6][S7][S8][S9] =1.0; in } - inttot =0; to DoubleCNT =0; + for(inti =1; I <=9; i++) - { the for(intj = i +1; J <=9; J + +) * { $ if(T[i] >0&& T[j] >0&& a[i][T[i]] = =a[j][T[j]])Panax Notoginseng { -t[i]--; thet[j]--; +tot++;//There are currently several options ACNT + = DFS (t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9]);//The probability of selecting all the remaining light after the I-Heap and the J-Heap thet[i]++; +t[j]++; - } $ } $ } - if(Tot >0) -D[S1][S2][S3][S4][S5][S6][S7][S8][S9] = CNT/(1.0* tot);//(1/tot) * CNT; current state probability the returnD[S1][S2][S3][S4][S5][S6][S7][S8][S9]; - }Wuyi intMain () the { - while(SCANF ("%s%s%s%s", s[1], s[2], s[3], s[4]) !=EOF) Wu { - for(inti =1; I <=4; i++) Abouta[1][i] = s[i][0] -'0';//A[i][j] is used to record the first J of Heap I $ for(inti =2; I <=9; i++) - { - for(intj =1; J <=4; J + +) - { Ascanf"%s", S[j]); +A[I][J] = s[j][0] -'0'; the } - } $memset (Vis,0,sizeof(Vis)); thememset (D,0,sizeof(d)); theDfs4,4,4,4,4,4,4,4,4);//all the heaps are 4 start search theprintf"%.6lf\n", d[4][4][4][4][4][4][4][4][4]); the } - return 0; in}
View Code
Uva1637double Patience (probability + memory search)