// 排列组合+组合数取模 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. UX结合需求实例化进行设计开发

    技  术  文  件 技术文件名称:实例化+UX需求分析实践:场景监控需求实例化 技术文件编号: 版        本:V1.0 共 32 页 (包括封面) 拟  制    廖开蒙.刀锋团队 审  核 ...

  2. 从SDE库文件手工删除SDE图层(转载)

    转载自:http://gis-conquer.blog.sohu.com/164467560.html 一.前言    虽然Catalog能解决这种问题,但是在特殊情况下也许这种方法有点用途.    ...

  3. HDOJ ----Phone List

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. NandFlash详述【转】

    NandFlash详述 转自:http://wenku.baidu.com/view/04d9330bb52acfc789ebc92f.html?re=view 1. 硬件特性: [Flash的硬件实 ...

  5. 第六讲(二) Hibernate HQL查询

    HQL查询:Criteria查询对查询条件进行了面向对象封装,符合编程人员的思维方式,不过HQL(Hibernate Query Lanaguage)查询提供了更加丰富的和灵活的查询特性,因此Hibe ...

  6. C语言之字节对齐

    在C语言编程中,有时为了达到减少运行的时间的目的,需要浪费一些空间:而有时为了节省空间,使它的运行时间增长.而字节对齐则是为了访问效率,用空间换取时间. 要掌握字节对齐,首先得明确一下四个概念: 1. ...

  7. 想找个计算器当本命?来试试UWP应用《纸书科学计算器》

    久违了.上次在博客园发文还是4年前,正是高中参加NOIP的时候.这4年里发生了很多事,乃至再次看到过去的文章时,仿佛看到了自己也不熟悉的风景.最近很想把我的博客重新拾起来,慢慢灌溉,写一些微不足道的技 ...

  8. 如何拷贝CMD命令行文本到粘贴板

    /********************************************************************* * 如何拷贝CMD命令行文本到粘贴板 * To copy ...

  9. I.MX6 Linux、Jni ioctl 差异

    /*********************************************************************** * I.MX6 Linux.Jni ioctl 差异 ...

  10. HDU1495 非常可乐

    解题思路:简单的宽搜,见代码: #include<cstdio> #include<cstring> #include<algorithm> #include< ...