zoukankan      html  css  js  c++  java
  • 象棋

    Description

    車是中国象棋中的一种棋子,它能攻击同一行或同一列中没有其他棋子阻隔的棋子。一天,小度在棋盘上摆起了许多車……他想知道,在一共N×M个点的矩形棋盘中摆最多个数的車使其互不攻击的方案数。他经过思考,得出了答案。但他仍不满足,想增加一个条件:对于任何一个車A,如果有其他一个車B在它的上方(車B行号小于車A),那么車A必须在車B的右边(車A列号大于車B)。
    现在要问问你,满足要求的方案数是多少 。

    Input

    第一行一个正整数T,表示数据组数。( T<=10)
    对于每组数据:一行,两个正整数N和M(N<=100000,M<=100000)。

    Output

    对于每组数据输出一行,代表方案数模1000000007(10^9+7)。

    Sample Input

    1
    1 1

    Sample Output

    1

    Hint

    求组合数的问题,由于数据较大,应该用求逆元的方法

    #include<iostream>
    #include<cstdio>
    #include<cmath> 
    #include<cstring>
    using namespace std;
    #define LL long long
    const int mod=1000000007;
    int t,m,n;
    
    LL fast_mod(LL x,int n)
    {
          LL ans=1;
          while(n)
          {
                if(n&1) ans=(ans*x)%mod;
                x=x*x%mod,n>>=1;
          }
          return ans;
    }
    
    LL C(int n,int m)
    {
          if(m>n) return 0;
          LL ans=1;
          for(int i=1;i<=m;i++) ans=ans*((n-m+i)*fast_mod(i,mod-2)%mod)%mod;
          return ans;
    }
    
    
    int main()
    {
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            int temp=0;
            if(n>m) swap(n,m);
            printf("%d
    ",C(m,n)%mod);
        }
        return 0;
    }
    /**********************************************************************
    	Problem: 2049
    	User: song_hai_lei
    	Language: C++
    	Result: AC
    	Time:64 ms
    	Memory:2024 kb
    **********************************************************************/
    


  • 相关阅读:
    手机的基本功能测试情景模式
    C#.net技术内幕04集合
    .net 发送电子邮件
    SQL:select case when(转)
    《 C#技术内幕》学习01IDisposable
    C#.net技术内幕03字符串
    点击确定后页面跳转
    SQL注入式攻击
    C#.NET技术内幕 02表达式
    window xp自带的功能之繁体字
  • 原文地址:https://www.cnblogs.com/csushl/p/9386547.html
Copyright © 2011-2022 走看看