对钉子DP,如果钉子存在DP[i+1][j]+=DP[i][j];
DP[i+1][j+1]+=DP[i][j];
如果不存在DP[i+2][j+1]+=4*DP[i][j];
见代码:(有一个比较坑爹的就是要用__Int64)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <stack>
#include <set>
#include <queue>
#define MAX(a,b) (a) > (b)? (a):(b)
#define MIN(a,b) (a) < (b)? (a):(b)
#define mem(a) memset(a,0,sizeof(a))
#define INF 1000000007
#define MAXN 20005
using namespace std; __int64 dp[][];
int N,M;
bool map[][]; __int64 gcd(__int64 a,__int64 b)//GCD求最大公约数
{
return a%b==?b:gcd(b,a%b);
} int main()
{
while(~scanf("%d%d%*c",&N,&M))
{
mem(dp);mem(map);
char str[]={};
int i,j;
dp[][]=;
for(i=;i<N;i++)
{
j=;
int t=;
gets(str);
while(str[j])
{
if(str[j] != ' ')map[i][t++] = str[j]=='*';
j++;
}
for(j=;j<t;j++)
{
if(map[i][j])
{
dp[i+][j]+=dp[i][j];
dp[i+][j+]+=dp[i][j];
}
else
{
dp[i+][j+]+=dp[i][j]*;
}
}
}
__int64 a = dp[N][M],b = (__int64)pow((double),N);
__int64 c = gcd(a,b);
printf("%I64d/%I64d\n",a/c,b/c); }
return ;
}