hdu 5894(组合数取模)
hannnnah_j’s Biological Test
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 681 Accepted Submission(s): 235
One day, she wants to test m students, thus she arranges n different seats around a round table.
In order to prevent cheating, she thinks that there should be at least k empty seats between every two students.
hannnnah_j
is poor at math, and she wants to know the sum of the solutions.So she
turns to you for help.Can you help her? The answer maybe large, and you
need to mod 1e9+7.
The next T lines were given n, m, k, respectively.
0 < m < n < 1e6, 0 < k < 1000
4 2 6
5 2 1
5
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const long long p = 1e9+;
typedef long long LL;
LL pow_mod(LL a,LL n)
{
LL ans=;
while(n)
{
if(n&) ans=ans*a%p;
a=a*a%p;
n>>=;
}
return ans;
}
LL cm(LL n,LL m,LL mod)
{
if(m>n) return ;
LL i,ans=,a,b;
for(i=; i<m; i++)
{
a=(n-i)%mod;
b=(m-i)%mod;
ans=ans*( a*pow_mod(b,mod-)%mod )%mod;
}
return ans;
}
LL lucas(LL n,LL m,LL p)
{
if(m==) return ;
return ( cm(n%p,m%p,p)*lucas(n/p,m/p,p) )%p;
} int main()
{
int T;
long long n,m,k;
scanf("%d",&T);
while(T--)
{
scanf("%lld %lld %lld",&n,&m,&k);
LL a = lucas(n-m*k-,m-,p);
LL c = pow_mod(m,p-)%p;
printf("%lld\n",((a*n)%p*c)%p); }
return ;
}
hdu 5894(组合数取模)的更多相关文章
- 排列组合+组合数取模 HDU 5894
// 排列组合+组合数取模 HDU 5894 // 题意:n个座位不同,m个人去坐(人是一样的),每个人之间至少相隔k个座位问方案数 // 思路: // 定好m个人 相邻人之间k个座位 剩下就剩n-( ...
- hdu 3944 DP? 组合数取模(Lucas定理+预处理+帕斯卡公式优化)
DP? Problem Description Figure 1 shows the Yang Hui Triangle. We number the row from top to bottom 0 ...
- 组合数取模Lucas定理及快速幂取模
组合数取模就是求的值,根据,和的取值范围不同,采取的方法也不一样. 下面,我们来看常见的两种取值情况(m.n在64位整数型范围内) (1) , 此时较简单,在O(n2)可承受的情况下组合数的计算可以 ...
- [BZOJ 3129] [Sdoi2013] 方程 【容斥+组合数取模+中国剩余定理】
题目链接:BZOJ - 3129 题目分析 使用隔板法的思想,如果没有任何限制条件,那么方案数就是 C(m - 1, n - 1). 如果有一个限制条件是 xi >= Ai ,那么我们就可以将 ...
- 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 ...
随机推荐
- 使用adb命令查看apk版本
adb devices (显示连接的设备) adb root (获取手机root权限) adb remount (重新挂载系统分区,使系统分区重新可写) adb shell (进入目标设备的L ...
- Codeforces 601D. Acyclic Organic Compounds(四个愿望一次满足)
trie合并的裸题...因为最多只有n个点,所以最多合并n次,复杂度$O(N*26)$. #include<iostream> #include<cstring> #inclu ...
- HDU4625 JZPTREE——第二类斯特林数
复杂度大概O(nk) 一些尝试:1.对每个点推出1,2,3,,,到k次方的值.但是临项递推二项式展开也要考虑到具体每个点的dist 2.相邻k次方递推呢?递推还是不能避免k次方的展开 k次方比较讨厌, ...
- Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp
B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- bzoj3938 Robot
3938: Robot Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 336 Solved: 112[Submit][Status][Discuss ...
- git 撤销上一次 commit
1.本地 commit,没有推到远程仓库 可以 git reset --soft <commit_id>,commit_id 是要回退到的某一版本 然后再进行修改,再commit, 如果需 ...
- Python-- Redis Set
一.无序集合 Set操作,Set集合就是不允许重复的列表 1.1 sadd(name, values) # name对应的集合中添加元素 1.2 smembers(name) # 获取name对应的集 ...
- Android Studio获取调试版SHA1和发布版SHA1的方法
前言: 当我们在集成高德地图定位功能到项目中的时候,需要用到发布版和调试版的安全码SHA1,所以今天我就来总结一下分别在Windows和Mac下是怎么来获取SHA1的,希望对大家有所帮助. 首先,统一 ...
- conda 虚拟环境
一.jupyter notbook (1)需要安装: conda install ipykernel (2)首先激活对应的conda环境 source activate 环境名称 (3)将环境写入no ...
- 我的Git之旅(1)---git安装、github注册以及一些基本命令
蚂蚁作为一个混码农届的新人来说,看到什么东西都觉得高大上的感觉.最近接触到了git,有种蠢蠢欲动的感觉,想 试一把.因此开启了我的Git之旅.废话不多说,开始我的git之旅. 1.git服务器的选择 ...