poj2279钩子公式

来源:互联网 发布:泛海三江主机编程视频 编辑:程序博客网 时间:2024/06/05 19:36

#include<iostream>
using namespace std;
__int64   c[10];
__int64   sum[155];
int gcd(int a,int b)
{
  if(a%b==0)
  return b;
  else
  return gcd(b,a%b);
}

int main()
{
   __int64 n,y,i,j,k,x,ans,cnt,tem;
    while(cin>>n)
    {
     if(n==0)
     break;
     for(i=1;i<=n;i++)
     cin>>c[i];
     cnt=0;

     for(i=1;i<=155;i++)
    {sum[i]=0;}
     i=1;
     while(i<=n)
     {
       for(j=1;j<=c[i];j++)
       {
            cnt++;
            for(k=i+1;k<=n;k++)
           {
            if(c[k]>=j)
            sum[cnt]++;
            else break;
           }
            sum[cnt]+=c[i]-j+1;
       }
       i++;
     }
     x=1;
     y=1;
       for(i=1;i<=cnt;i++)
      {
         x*=i;
         y*=sum[i];
         tem=gcd(x,y);
         if(tem!=1)
         {x/=tem;y/=tem;}
      }
      ans=x/y;
      cout<<ans<<endl;
     }
     system("pause");
     return 0;
}
下钩子公式..对有效格子编号1.2.3....n

对于一个有效格子A_i,其上面的有效格子数为Up_i,其右边的有效格子数为Right_i

则答案为Ans=n!/((Up_1 + Right_1 +1)*(Up_2 + Right_2 +1)*....*(Up_n + Right_n +1))

本题目目前使用此公式水过,但是不会证明~~~

原创粉丝点击