1656:Combination
一本通1656:Combination
1656:Combination
时间限制: 1000 ms 内存限制: 524288 KB
提交数: 89 通过数: 49
【题目描述】
原题来自:BZOJ 2982
LMZ 有 n
个不同的基友,他每天晚上要选 m 个进行 [河蟹],而且要求每天晚上的选择都不一样。那么 LMZ 能够持续多少个这样的夜晚呢?当然,LMZ 的一年有 10007 天,所以他想知道答案 mod10007
的值。
【输入】
第一行一个整数 t
,表示有 t
组数据;
接下来 t
行每行两个整数 n,m
,如题意。
【输出】
t
行,每行一个数,为 (nm)mod10007
的答案。
【输入样例】
4
5 1
5 2
7 3
4 2
【输出样例】
5
10
35
6
【提示】
数据范围与提示:
对于全部数据,1≤t≤200,1≤m≤n≤2×108
。
这道题没有什么含金量但是题目本身很神♂奇
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=;
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;
}
inline ll power(ll a,ll b)
{
ll res=;
while(b)
{
if(b&) res=res*a%mod; a=a*a%mod; b>>=;
}
return res;
}
inline ll C(ll n,ll m)
{
ll n0=,m0=;
for(ll i=n-m+;i<=n;i++) n0=n0*i%mod;
for(ll i=;i<=m;i++) m0=m0*i%mod;
return n0*power(m0,mod-)%mod;
}
inline ll Lucas(ll n,ll m)
{
if(m==) return ;
return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main()
{
int t;
t=read();
ll n,m;
while(t--)
{
n=(ll)read();
m=(ll)read();
printf("%lld\n",Lucas(n,m));
}
return ;
}
1656:Combination的更多相关文章
- 【BZOJ】1656:[Usaco2006 Jan]The Grove 树木(bfs+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1656 神bfs! 我们知道,我们要绕这个联通的树林一圈. 那么,我们想,怎么才能让我们的bfs绕一个 ...
- 数字组合问题:Combination,CombinationSum,CombinationSum2,CombinationSum3
Combination问题描述:给定n和k,找出1-n之间所有k个数的组合,例如:n=3,k=2,返回 [[1,2] [1,3] [2,3]] 算法分析:利用递归.递归边界就是curr.size( ...
- LeetCode OJ:Combination Sum II (组合之和 II)
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- LeetCode OJ:Combination Sum (组合之和)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- LeetCode OJ:Combination Sum III(组合之和III)
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- 540A: Combination Lock
题目链接:http://codeforces.com/problemset/problem/540/A 题意: 输入的两个长度一样的数,求对应位置的某位数到下一个数需要最小的步长,每次只能先前或先后走 ...
- 一本通1656Combination
1656:Combination 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:BZOJ 2982 LMZ 有 n 个不同的基友,他每天晚上要选 ...
- [LeetCode] Combination Sum IV 组合之和之四
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- [LeetCode] Combination Sum III 组合之和之三
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
随机推荐
- css border 三角形阴影(不规则图形阴影) & 多重边框的制作
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! border 的组合写法 border:border-width border-style border- ...
- (十一)shiro与ssm整合
所有代码在:here pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="h ...
- 奇妙的算法【9】YC每个小孩的糖果数,找公约数,最少硬币数
1,每个小孩的糖果数量是多少 有p个小孩,c个糖果,刚开始第1个小孩发一个糖果,第2个小孩发两个糖果,第p个小孩发p个糖果,如果糖果没有发完,就接着[注意]第1个小孩发p+1个糖果.....第p个小孩 ...
- 排序算法原理及代码实现(c#)
1.插入排序 把第一个元素看做已排序数组放在有序数组中,从第二个元素开始,依次把无序数组元素取出和有序数组中的元素逐个比较,并放在有序数组的正确位置上. /// <summary> /// ...
- POJ1083(Moving Tables)--简单模拟
题目链接:http://poj.org/problem?id=1083 如图所示在一条走廊的两侧各有200个房间,现在给定一些成对的房间相互交换桌子,但是走廊每次只能通过一组搬运, 也就是说如果两个搬 ...
- clipboard兼容各个浏览器,不需要设置权限
解决方案:用clipboard.js插件 注意要引用clipboard.js文件 案例: 将文本赋值给剪切板 <button class="btn">Copy</ ...
- Spring Boot实现自定义注解
在Spring Boot项目中可以使用AOP实现自定义注解,从而实现统一.侵入性小的自定义功能. 实现自定义注解的过程也比较简单,只需要3步,下面实现一个统一打印日志的自定义注解: 1. 引入AOP依 ...
- idou老师教你学Istio12 : Istio 实现流量镜像
微服务为我们带来了快速开发部署的优秀特性,而如何降低开发和变更的风险成为了一个问题.Istio的流量镜像,也称为影子流量,是将生产流量镜像拷贝到测试集群或者新的版本中,在引导实时流量之前进行测试,可以 ...
- 读HTTP权威指南的体会
国庆期间,我读了HTTP权威指南一书,现在我把总节为大家讲一下: Web 浏览器.服务器和相关的Web 应用程序都是通过HTTP 相互通信的.HTTP 是 现代全球因特网中使用的公共语言. 是对HTT ...
- jade-for-each-while
if else还是for循环,在jade里面都是可执行的代码 for循环 - var lession = {course:'jade', level:'high'} - for (var k in l ...