// 排列组合+组合数取模 HDU 5894
// 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数
// 思路:
// 定好m个人 相邻人之间k个座位 剩下就剩n-(m+1)*k个座位
// 剩下座位去插m个不同的盒子==就等价n个相同的球放m个不同的盒子
// 然后组合数出来了
// 乘n的话是枚举座位,除m是去掉枚举第一个座位的时候,剩下人相邻的座位相对不变的情况 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+;
const int N = 1e6+;
const int maxx = ;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int f[N];
int inv(int x){
int ret=,y=mod-;
while(y){
if(y&)ret=1ll*ret*x%mod;
y>>=;x=1ll*x*x%mod;
}
return ret;
}
int C(int n,int m){
if(n<m)return ;
int ret=1ll*f[n]*inv(f[m])%mod;
ret=1ll*ret*inv(f[n-m])%mod;
return ret;
}
int lucas(int n,int m){
if(m == ) return ;
return 1ll*C(n % mod, m % mod) * lucas(n / mod, m / mod) % mod;
} void init(){
f[]=;
for(int i=;i<=N-;++i)f[i]=1ll*i*f[i-]%mod;
} int main(){
init();
int T;
scanf("%d",&T);
while(T--){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
if(m==){
printf("%d\n",n);
continue;
}
LL res=n-(m+)*k;
if(res<){
printf("0\n");
continue;
}
LL tem=lucas(n-m*k-,m-);
LL ans=((tem)%mod)*n%mod;
printf("%d\n",(ans*inv(m))%mod);
}
return ;
}

修正一下,加一组样列:

 n=5,m=1,k=1000
这时候用res的话 必须判m==1
其实可以一起去掉,直接lucas也a
数据太重要了

排列组合+组合数取模 HDU 5894的更多相关文章

  1. hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)

    DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...

  2. [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】

    题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...

  3. 组合数取模Lucas定理及快速幂取模

    组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1)  , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...

  4. lucas定理解决大组合数取模

    LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...

  5. 2015 ICL, Finals, Div. 1 Ceizenpok’s formula(组合数取模,扩展lucas定理)

    J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. BZOJ_2142_礼物_扩展lucas+组合数取模+CRT

    BZOJ_2142_礼物_扩展lucas+组合数取模 Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同 ...

  7. 组合数取模&&Lucas定理题集

    题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020  输出组合数C(n, m) mod p (1 ...

  8. 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数

    typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...

  9. 组合数取模(lucas定理+CRT合并)(AC)

    #include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inlin ...

随机推荐

  1. iScrolljs 模拟android相册

    var showBigImage = new iScroll('showBigImage', { snap: 'div', snapThreshold: 480, momentum: false, z ...

  2. [原]HDU-1598-find the most comfortable road(暴力枚举+Kruskal最小生成树)

    题意: 给出一个图,然后Q个询问,每次询问从一个节点到另一个节点,联通图中的“最大边和最小边之差”的最小值,但如果节点之间不连通,则输出-1. 思路:由于询问Q < 11,m < 1000 ...

  3. NDK(11)Android.mk编译APK模板

    转自 :  http://hubingforever.blog.163.com/blog/static/1710405792011656434982/ 以下仅是使用Android.mk编译APK程序的 ...

  4. plsql programming 19 触发器

    挂起语句, 是指数据库 Hang 到那不能动了, 触发的. 1. DML 触发器 这种类型的触发器对于开发人员都很常见, 其他类型的触发器主要是给DBA使用的. 配置触发器,我们需要回答以下问题: 触 ...

  5. 【Todo】各种排序整理

    今天面试别人,问到堆排序.发现自己都记不太清楚了. 堆排序 从小到大排序,要用到的是,最大堆. 过程是最大堆,堆顶的最大的元素,调换到数组最后,依次进行.最后达到从小到大的效果. 归并排序 可以看这个 ...

  6. word-pattern(mock)

    注意: // String要用equals,不然比较结果不对,会出bug// 使用String.split // boolean打印用 %b  // abba 对应 cccc 也不行, 所以要用set ...

  7. bzoj2982: combination

    借(cao)鉴(xi)自popoqqq大爷的lucas定理的写法 #include<cstdio> #include<cstring> #include<cctype&g ...

  8. memcached内存管理及key value长度限制

    1)什么是内存碎片?内存是大小有限的资源.例如把内存比作一张小床,来了一个小伙伴,可以睡下,再来一个小伙伴也能睡下.现在两个人了,他们点了差不多的大小的位置(资源),位置还有剩下.然后再来一个小胖子, ...

  9. mysql日期函数(转)

    MySQL 获得当前日期时间 函数 获得当前日期+时间(date + time)函数:now() mysql> select now(); +---------------------+ | n ...

  10. Jave 鼠标点击画太极 PaintTaiji (整理)

    package demo; /** * Jave 鼠标点击画太极 PaintTaiji (整理) * 声明: * 又是一份没有注释的代码,而且时间已经久远了,不过代码很短,解读起来应该 * 不会很麻烦 ...