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 ...
随机推荐
- 如何在 ASP.NET 应用程序中实现模拟用户身份(在ASP.NET中以管理员身份运行网站)
前言 在实际的项目开发中,我们可能会需要调用一些非托管程序,而有些非托管程序需要有更高的身份权限才能正确执行.本文介绍了如何让IIS承载的ASP.NET网站以特定的账户执行,比如Administrat ...
- Android APK打包流程
简单build流程图 官网给了我们一张非常简单的编译.打包.apk生成内容以及签名的图片.图片大体介绍了从Project到运行到设备或者模拟器的一个大体流程,我们也从中看到一个完整的apk包含如下内容 ...
- Codeforces Round #415 (Div. 2) A B C 暴力 sort 规律
A. Straight «A» time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 安装黑苹果的config.plist
前提条件:有mac真机.目前在测试虚拟机可行性 第一步:制作U盘启动盘 1.在 app store 下载 mac OS sierra 镜像 2.格式化 U 盘,gpt 格式 3.执行以下命令(具体名称 ...
- springboot用mybatis-generator自动生成mapper和model
转:http://blog.csdn.net/u011493599/article/details/53928379 1.在pom.xml里添加maven插件 <plugin> <g ...
- TCP ------ 抓包分析(seq ack)
总结: 1.ACK包可以和其他包合在一起,比如ACK包可以携带数据 2.可以接收多个数据包后,一次性给一个应答,不用每个数据包一一对应给应答 3.在通信过程中,通过接收到的包的ack值可以判断是否是上 ...
- Tensorflow BatchNormalization详解:2_使用tf.layers高级函数来构建神经网络
Batch Normalization: 使用tf.layers高级函数来构建神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 吴恩达deeplearningai课程 课程笔 ...
- HTML5-Y音频与视频
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 重构改善既有代码设计--重构手法15:Remove Middle Man (移除中间人)
某个类做了过多的简单委托动作.让客户直接调用受托类. 动机:在Hide Delegate (隐藏委托关系)的“动机”中,谈到了“封装委托对象”的好处.但是这层封装也是要付出代价的,它的代价是:每当客户 ...
- 详解ASP.NET4 GridView的四种排序样式
与ASP.NET 的其他Web控件一能够,Gridview控件拥有很多不同的CSS样式属性设置,包括象CssClass,Font字体,ForeColor,BackColor,BackColor, Wi ...