标签:
http://poj.org/problem?id=1189
Description
,其中i为格子的编号,从左至右依次为0,1,...,n。 
Input
Output
Sample Input
5 2 * * . * * * * . * * * * * * *
Sample Output
7/16
/**
poj1189 简单dp
题目大意:又是中文题~
解题思路; 总共会出现2^n种情况,我们一开始就假设有2^n个球在(1,1)点往下落。
对于每一个没有挖掉的钉子(i,j):dp[i+1][j]+=dp[i][j]/2; dp[i+1][j+1]+=dp[i][j]/2;
对于挖掉的钉子(i,j):dp[i+2][j+1]+=dp[i][j];
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
bool a[2555];
int n,m;
LL dp[55][55];
LL gcd(LL x,LL y)
{
if(y==0)return x;
return gcd(y,x%y);
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
int k=1;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
char str[12];
scanf("%s",str);
if(str[0]=='*')
{
a[k++]=true;
}
else
{
a[k++]=false;
}
//printf("%d\n",a[k-1]);
}
//puts("");
}
memset(dp,0,sizeof(dp));
dp[1][1]=1LL<<n;
for(int i=1; i<=n; i++)
{
int x=i*(i-1)/2;
for(int j=1; j<=i; j++)
{
if(a[j+x])
{
dp[i+1][j]+=dp[i][j]/2;
dp[i+1][j+1]+=dp[i][j]/2;
}
else
{
dp[i+2][j+1]+=dp[i][j];
}
}
}
LL x=1LL<<n;
LL y=dp[n+1][m+1];
LL g=gcd(x,y);
printf("%lld/%lld\n",y/g,x/g);
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/lvshubao1314/article/details/44488743