百(垃)度(圾)之星初赛B hdu6114

Chess

题意:中文题

思路:其实就是在n个格子上放m个棋子(n>=m)(xjb套Lucas的板子...

AC代码:

#include "iostream"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define ll long long
#define endl ("\n")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

ll     exp_mod(ll a, ll b, ll p){
    ll res = 1;
    while(b != 0){
        if(b&1) res = (res * a) % p;
        a = (a*a) % p;
        b >>= 1;
    }
    return res;
}
ll Comb(ll a, ll b, ll p){
    if(a < b)   return 0;
    if(a == b)  return 1;
    if(b > a - b)   b = a - b;

    ll ans = 1, ca = 1, cb = 1;
    for(ll i = 0; i < b; ++i){
        ca = (ca * (a - i))%p;
        cb = (cb * (b - i))%p;
    }
    ans = (ca*exp_mod(cb, p - 2, p)) % p;
    return ans;
}
ll C(int n, int m, int p){
     ll ans = 1;
     while(n&&m&&ans){
        ans = (ans*Comb(n%p, m%p, p)) % p;
        n /= p;
        m /= p;
     }
     return ans;
}

int n,m;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T; cin>>T;
    while(T--){
        cin>>n>>m;
        if(n<m ) swap(n,m);
        cout<<C(n,m,mod)<<endl;
    }
    return 0;
}

 

posted on 2017-08-13 19:42  lazzzy  阅读(131)  评论(0编辑  收藏  举报

导航