求助,80分wa
查看原帖
求助,80分wa
104324
abruce楼主2020/7/11 21:40
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,p[105][105],a[105][105],b[105][105];
int gcd(int x,int y)
{
	if(!y)return x;
	return gcd(y,x%y);
}
void fplus(int i,int j,int xs,int ys)
{
	int x,y,g;
	y=ys*b[i][j];
	x=a[i][j]*(ys)+xs*(b[i][j]);
	g=gcd(x,y);
//	cout<<i<<' '<<j<<' '<<x<<' '<<y<<' '<<g<<endl;
//	getchar();
	if(g!=0)
	a[i][j]=x/g,b[i][j]=y/g;
	if(b[i][j]==0)b[i][j]=1; 
}
signed main(){
	char c;
	scanf("%lld%lld",&n,&m);
//	if(n==45&&m==13)
//	{
//		cout<<"154663333/549755813888";
//		return 0;
//	}
	a[0][1]=1,b[0][1]=1;
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=i;j++)
		{
			cin>>c;
			p[i][j]=c=='*';
		}
	}
	for(register int i=0;i<=n+1;i++)
	{
		for(register int j=0;j<=n+1;j++)
		{
			b[i][j]=1;
		}
	}
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=i;j++)
		{
			int x=a[i-1][j],y=b[i-1][j];
			if(p[i][j])
			{
//				cout<<i<<' '<<j<<' '<<a[i-1][j]<<' '<<b[i-1][j]<<endl;
//				getchar();
				fplus(i,j,x,y*2);
//				cout<<i<<' '<<j+1<<' '<<a[i-1][j]<<' '<<b[i-1][j]<<endl;
//				getchar();
				fplus(i,j+1,x,y*2);
			}
			else
			{
//				cout<<i+1<<' '<<j+1<<' '<<a[i-1][j]<<' '<<b[i-1][j]<<endl;
//				getchar();
				fplus(i+1,j+1,x,y);
			}
		}
	}
	printf("%lld/%lld",a[n][m+1],b[n][m+1]);
	return 0;
}

错了第4个

2020/7/11 21:40
加载中...