zoukankan      html  css  js  c++  java
  • 百(垃)度(圾)之星初赛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 ("
    ")
    #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;
    }
  • 相关阅读:
    边长为n的正六边形
    simsimi无限次数api微信公众平台
    仿QQ空间送礼物功能
    asp.net动态输出404
    瀑布流布局并实现自动加载
    微信浏览器的HTTP_USER_AGENT
    AutoIt学习系列:目录
    PDA开发系列:Google地图接口
    WinCE、Windows Mobile GPRS连接类
    PDA开发系列:数据库的选择
  • 原文地址:https://www.cnblogs.com/max88888888/p/7354487.html
Copyright © 2011-2022 走看看