1. 程式人生 > >HDU 5698:瞬間移動(排列組合)

HDU 5698:瞬間移動(排列組合)

AC程式碼:

#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef long long LL;
const LL mod = 1000000007;
const int maxn = 100010;
LL JC[maxn];
void createTable() {
    JC[0] = 1;
    for(int i = 1; i < maxn; i++) {
        JC[i] = (i*JC[i-1])%mod;
    }
}
LL resMod(LL x,LL pow) {
    LL ans,res;
    ans = 1;
    res = x;
    while(pow) {
        if(pow&1) {
            ans = (ans*res)%mod;
        }
        res = (res*res)%mod;
        pow = pow>>1;
    }
    return ans;
}
LL C(int n,int m) {
    LL temp = (JC[m]*JC[n-m])%mod;
    //求temp的逆元,由於mod是素數,因此可以用小費馬定理求逆元
    LL resTemp = resMod(temp,mod-2);
    LL ans = (JC[n]*resTemp)%mod;
    return ans;
}
int main() {
    int N,M;
    createTable();
    while(~scanf("%d%d",&N,&M)) {
        int Min = min(N,M);
        int Max = max(N,M);
        LL ans = 0;
        for(int i = 0; i <= Min-2; i++) {
            ans += C(Min-2,i)*C(Max-2,i);
            ans = ans%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


相關推薦

HDU 5698瞬間移動排列組合

AC程式碼: #include <iostream> #include <stdio.h> #include <algorithm> using namespace std; typedef long long LL;

HDU 5698瞬間移動組合數,逆元

x和y分開考慮,在(1,1)到(n,m)之間可以選擇走i步。就需要選i步對應的行C(n-2,i)及i步對應的列C(m-2,i)。相乘起來。 假設$m\leq n$$$\sum_{i=1}^{m-2} C_{n-2}^i\cdot C_{m-2}^i=\sum_{i=1}^{m-2} C_{n-2}^i\cd

HDU 2200 Eddy's AC難題排列組合

Eddy's AC難題 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submissi

2018.10.25 uoj#308. 【UNR #2】UOJ拯救計劃排列組合

傳送門 有一個顯然的式子:Ans=∑A(n,i)∗用i種顏色的方案數Ans=\sum A(n,i)*用i種顏色的方案數Ans=∑A(n,i)∗用i種顏色的方案數 這個東西貌似是個NPCNPCNPC。 於

排列組合wannafly28-d

#include<bits/stdc++.h> using namespace std; const int maxn = 2e6+100; typedef long long ll; typedef pair<int, int> pi

Round Numbers 排列組合

The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo

POJ - 1850 Code排列組合

Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known sys

4123 && ALGO-165 Glenbow Museum排列組合

題目連結:http://lx.lanqiao.cn/problem.page?gpid=T461點選開啟連結 演算法訓練 Glenbow Museum   時間限制:1.0s   記憶體限制:256.0MB 問題描述   卡城著名的格林堡博物館是加拿大西部

bzoj3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛排列組合

geo mes can line llc names 裏的 簡單的 tro 原題鏈接 題目描述:約翰要帶N(1≤N≤100000)只牛去參加集會裏的展示活動,這些牛可以是牡牛,也可以是牝牛.牛們要站成一排.但是牡牛是好鬥的,為了避免牡牛鬧出亂子,約翰決定任意兩只牡牛之間至少

UOJ 2017NOI Round #2 T1:UOJ拯救計劃排列組合

Description 小O和小I一直喜歡打 UOJ 的比賽,然而等了半個丁酉年卻也沒能等到下一次比賽。眼看著 NOI 即將到來,他們決定一探究竟,找出 UOJ 沉寂的真正原因! 終於有一天,他們得知 UOJ 的管理層全都被兩個一心想摧毀 OI 界的大魔王

next_permutation排列組合函式的用法

小明十分聰明,而且十分擅長排列計算。比如給小明一個數字5,他能立刻給出1-5按字典序的全排列,如果你想為難他,在這5個數字中選出幾個數字讓他繼續全排列,那麼你就錯了,他同樣的很擅長。現在需要你寫一個程式來驗證擅長排列的小明到底對不對。

插板法排列組合

轉自(http://www.cnblogs.com/justPassBy/p/4600772.html) 插板法的條件() (1)每個元素都是相同的 (2)分成的組,每組的元素不為空 就比如下面這個例子,分出來的組的元素是不為空的   原始問題: 將10個相同的球放到3個不同的籃子裡面去,

HDU 2546飯卡01揹包

飯卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 41634    Accepted Submission(

HDU 5698 瞬間移動費馬、逆元

題目:有一個無限大的矩形,初始時你在左上角(即第一行第一列),每次你都可以選擇一個右下方格子,並瞬移過去(如從下圖中的紅色格子能直接瞬移到藍色格子),求到第nn行第mm列的格子有幾種方案,答案對1000

hdu 1799 循環多少次?排列組合公式

oid mil 每次 .cn 可能性 ble include 復制 三次 循環多少次? Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

HDU 1051 Wooden Sticks貪心

memory others sticks mac resp setup cto ret cst Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768

【專題】計數問題排列組合,容斥原理,卡特蘭數

spl 狀態 ans 補集 方便 常用 括號 inf 不存在 ---下面都是學習的筆記,還沒有整理,比較淩亂,有需自取吧。--- 【排列組合】 <加法原理>做一件事情有n個方法,第i個方法有pi種方案,則一共有p1+p2+...+pn種方案。 <乘法原理&

題解報告hdu 2087 剪花布條KMP入門

不變 indent spa bottom fix href pac transform eight 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 Problem Description 一塊花布條,裏面有些圖案,另有

HDU-1003Max Sum優化

with space bug 初始 problem -a 劉汝佳 但是 n) Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S

HDU-6035Colorful Tree虛樹+DP

node different ase 得到 第一題 false all 直接 files 這裏有三道長得像的題: 一: HDU6036: There is a tree with nn nodes, eac