一眼题...输出分数格式才是这题的难点QAQ
学习了分数结构体...
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #define ll long long using namespace std; const int maxn=60,inf=1e9; struct fra{ll u,d;fra(ll a=0,ll b=1){u=a,d=b;}}f[maxn][maxn]; int n,m; bool mp[maxn][maxn]; int readch() { char ch=getchar(); while(ch==' '||ch==' '||ch==' '||ch==' ')ch=getchar(); return ch=='*'; } ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} void sim(fra &x){ll t=gcd(x.u,x.d);x.u/=t;x.d/=t;} fra operator+(fra x,fra y) { ll t=gcd(x.d,y.d); fra c=fra(y.d/t*x.u+x.d/t*y.u,x.d/t*y.d); return sim(c),c; } fra operator*(fra x,fra y) { fra c=fra(x.u*y.u,x.d*y.d); return sim(c),c; } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) mp[i][j]=readch(); f[1][1]=fra(1,1); for(int i=1;i<=n;i++) for(int j=1;j<=i;j++) if(mp[i][j])f[i+1][j]=f[i+1][j]+f[i][j]*fra(1,2),f[i+1][j+1]=f[i+1][j+1]+f[i][j]*fra(1,2); else f[i+2][j+1]=f[i+2][j+1]+f[i][j]; printf("%lld/%lld",f[n+1][m+1].u,f[n+1][m+1].d); return 0; }