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 ...
随机推荐
- 20135239 益西拉姆 linux内核分析 跟踪分析Linux内核的启动过程
回顾 1.中断上下文的切换——保存现场&恢复现场 本节主要课程内容 Linux内核源代码简介 1.打开内核源代码页面 arch/目录:支持不同CPU的源代码:其中的X86是重点 init/目录 ...
- Codeforces 671D. Roads in Yusland(树形DP+线段树)
调了半天居然还能是线段树写错了,药丸 这题大概是类似一个树形DP的东西.设$dp[i]$为修完i这棵子树的最小代价,假设当前点为$x$,但是转移的时候我们不知道子节点到底有没有一条越过$x$的路.如果 ...
- Spring MVC入门示例
1.新建一个Java Web项目 2.导入jar包 3.在WEB-INF下面建一个hello.jsp页面. <%@ page language="java" import=& ...
- Java--Inheritance constructor继承中的构造方法问题(二)
看了前辈的博客,觉得这两点说的精辟:子类构造方法必须要调用父类的某个构造方法:被子类调用的父类构造方法在父类中必须是存在的. 上篇的例子有一点不明白,子类继承了父类的成员变量,父类的构造函数里引用了该 ...
- Codeforces Round #305 (Div. 2) D 维护单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- HDU 4722 数位dp
Good Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- poj 1655 树的重心
Balancing Act Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13178 Accepted: 5565 De ...
- NYOJ--703
原题链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=703 分析:先考虑不受限制的情况,此时共可以修n*(n-1)/2条隧道:所有的place组 ...
- 折腾到死:matlab7.0 安装
matlab7.0应该是2004年的东西了吧,装起来相当费劲!为什么不用更高的版本呢?其实我也想,之前安装的2013a安装包就5个多G,安装完之后就十多个G了.我习惯将软件安装到C盘,可怜我那100G ...
- .Net并行编程系列之一:并行基础
现在普通PC平台上面多核处理器的普及,让我们领教了能够利用多核进行并行计算的软件的处理能力,同时继承更多地核心正是当前处理器发展的趋势. 但是作为一个.NET开发人员,是否有时候会发现你的程序占用了其 ...