排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 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 ;
}
修正一下,加一组样列:
排列组合+组合数取模 HDU 5894的更多相关文章
- hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...
- [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】
题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...
- 组合数取模Lucas定理及快速幂取模
组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1) , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...
- lucas定理解决大组合数取模
LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...
- 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 ...
- BZOJ_2142_礼物_扩展lucas+组合数取模+CRT
BZOJ_2142_礼物_扩展lucas+组合数取模 Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同 ...
- 组合数取模&&Lucas定理题集
题集链接: https://cn.vjudge.net/contest/231988 解题之前请先了解组合数取模和Lucas定理 A : FZU-2020 输出组合数C(n, m) mod p (1 ...
- 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数
typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...
- 组合数取模(lucas定理+CRT合并)(AC)
#include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inlin ...
随机推荐
- PHP高级特性二之文件处理
PHP中的文件处理也是一个相当重要的模块,这一篇的主要内容就是PHP中文件系统的简介. 文件系统用途 1. 项目处理都离不开文件处理 2. 可以用文件长时间保存数据 3. 建立缓存,在服务器中进行文件 ...
- 同一Session中的aspx页面的并发限制
项目中客户端采用WebBrowser展示aspx页面,用户有可能打开带多个带WebBrowser的winform窗体.此时,如果其中一个的WebBrowser的aspx页面响应较长的话,其他窗体中的W ...
- 很实用的js限制不让输入其他字符,只让输入数字和 js生成UUID
onkeyup="this.value=this.value.replace(/\D/g,'')" js生产UUID var createUUID = (function (uui ...
- IntelliJ IDEA12.1.1 使用 相关记录
最近在切换ide 从eclipse平台上转移到 IDEA 其它的都比较容易,让我烦恼的是使用idea 发布工程,使用tomcat 调试 热部署.期间碰到各种问题,纠结好久了:终于成功完成了,特意记 ...
- 安全删除mysql binlog日志
命令行下执行 show binary logs; purge binary logs to 'mysql-bin.000070';
- Java NIO读书笔记
一.Java IO与NIO区别: (1)Java NIO提供了与标准IO不同的IO工作方式: Channels and Buffers(通道和缓冲区):标准的IO基于字节流和字符流进行操作的,而NIO ...
- 转载]IOS LBS功能详解[0](获取经纬度)[1](获取当前地理位置文本 )
原文地址:IOS LBS功能详解[0](获取经纬度)[1](获取当前地理位置文本作者:佐佐木小次郎 因为最近项目上要用有关LBS的功能.于是我便做一下预研. 一般说来LBS功能一般分为两块:一块是地理 ...
- HDU 3555 Bomb (数位DP-记忆化搜索模板)
题意 求区间[1,n]内含有相邻49的数. 思路 比较简单的按位DP思路.这是第一次学习记忆化搜索式的数位DP,确实比递推形式的更好理解呐,而且也更通用~可以一般化: [数位DP模板总结] int d ...
- 【C#学习笔记】从粘贴板复制文本
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- hibernate封装查询,筛选条件然后查询
// 封装查询条件 @Test public void transmitParameter() { Map map = new HashMap<String, String>(); // ...