UPDATE:代码里加了些注释
简单DP,注意数据爆int
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 #define int long long 5 namespace the_Death{ 6 int dp[60][60],n,m,map[60][60],ans; 7 inline int gcd(int x,int y){return y?gcd(y,x%y):x;} 8 //dp[i][j]->the possible for arrive at (i,j) 9 //dp[i+1][j],dp[i+1][j+1]->dp[i][j]/2<--'*' 10 //dp[i+2][j+1]->dp[i][j]<--'.' 11 signed main(){ 12 scanf("%lld%lld",&n,&m); 13 for(register int i=1;i<=n;i++) 14 for(register int j=1;j<=i;j++){ 15 char c=getchar(); 16 while(c!='.'&&c!='*') c=getchar(); 17 map[i][j]=c; 18 } 19 dp[1][1]=1ll<<n; 20 //小trick:我不想开double,也不会单独去存一个分子&&分母 21 //所以我默认的基数只要足够大,大到即使除2除到最后最小也是1就好了 22 //最多除N次2,所以默认基数为2^n就好了 23 for(register int i=1;i<=n;i++){ 24 for(register int j=1;j<=i;j++){ 25 if(map[i][j]=='.') 26 dp[i+2][j+1]+=dp[i][j]; 27 else 28 dp[i+1][j]+=dp[i][j]/2, 29 dp[i+1][j+1]+=dp[i][j]/2; 30 } 31 } 32 int ggcd=gcd(dp[n+1][m+1],dp[1][1]); 33 if(dp[n+1][m+1]==0) printf("0/1"); 34 else printf("%lld/%lld",dp[n+1][m+1]/ggcd,dp[1][1]/ggcd); 35 //system("pause"); 36 } 37 } 38 signed main(){ 39 the_Death::main();return 0; 40 }