Mathematical expectation/Markov process
dp/Memory Search
Rujia Teacher petition on the example ...
1 //UVA 117622#include <vector>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <iostream>7#include <algorithm>8 #defineRep (i,n) for (int i=0;i<n;++i)9 #defineF (i,j,n) for (int i=j;i<=n;++i)Ten #defineD (i,j,n) for (int i=j;i>=n;--i) One using namespacestd; A intGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} the while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*=Sign ; - } - Const intn=1e6+Ten; + #defineDebug - /******************tamplate*********************/ + intPrime[n],tot; A BOOLCheck[n]; at - voidGETPR (intN) { -memset (check,0,sizeofcheck); -F (I,2, N) { - if(!check[i]) prime[tot++]=i; - Rep (j,tot) { in if(i*prime[j]>n) Break; -check[i*prime[j]]=1; to } + } - } the BOOLVis[n]; * DoubleF[n]; $ Doubledpintx) {Panax Notoginseng if(x==1)return 0.0; - if(Vis[x])returnF[x]; thevis[x]=1; + Double&ans =F[x]; A intg=0, p=0; ans=0; the Rep (j,tot) { + if(prime[j]>x) Break; -p++; $ if(x%prime[j]==0) {g++; ANS+=DP (x/prime[j]);} $ } -ans= (ans+p)/G; - returnans; the } - intMain () {Wuyi #ifndef Online_judge theFreopen ("11762race_to_1.in","R", stdin); -Freopen ("11762race_to_1.out","W", stdout); Wu #endif -GETPR (n2); About intt=getint (); $F (T,1, T) -printf"Case %d:%.10lf\n", T,DP (Getint ())); - return 0; -}
View Code
"UVA" "11762" Race to 1 (get 1)