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 ...
随机推荐
- 使用jdk8 stream简化集合操作
使用stream的前提是对lambda表达式和函数式接口有一定的了解,同时对方法引用和普通传参的区别有一定的认识. stream的三大特性:1.不存储数据2.不改变源数据3.延时执行. stream优 ...
- LeetCode 1047. Remove All Adjacent Duplicates In String
1047. Remove All Adjacent Duplicates In String(删除字符串中的所有相邻重复项) 链接:https://leetcode-cn.com/problems/r ...
- Project Oberon
Project Oberon Project Oberon http://www.projectoberon.com/ Project Oberon 28.11.2018 / 11.12.2018 ...
- Django rest-framework框架-组件之视图
视图: a. django class Test(View): ... b. rest_framework class Test(APIView): ... c. GenericAPIView 一般不 ...
- Java 面向对象(七)多态
一.多态概述(Polymorphism) 1.引入 多态是继封装.继承之后,面向对象的第三大特性. 通过不同的事物,体现出来的不同的形态.多态,描述的就是这样的状态.如跑的动作,每个动物的跑的动作就是 ...
- iOS中的分类(category)和类扩展(extension)
今天在研究swift的时候看到了分类和扩展.这是两个十分重要有用的功能,但是之前用的不多,没有深入了解过,在今天就从头理一遍. 一.分类(Category): 概念: 分类(Category)是OC中 ...
- Java面试容器,collection,list,set
1.容器指的是可以容纳其他对象的对象. 2.collection/set/list的联系和区别? (1)collection是Java集合顶级接口,存储一组不唯一,无序的对象: (2)list接口 ...
- json _ ajax_跨域
1 json 1 js 对象 语法: 1 通过一对{}表示一个对象 2 在{}中允许通过 key:value 的形式来表示属性 3 多对的属性和值之间使用 , 隔开 2 什么中JSON 按照JS对象的 ...
- 第四章、drf框架 - 三大认证组件 | 认证组件 | 权限组件 | 频率组件
目录 RBAC 基于用户权限访问控制的认证 - Role-Based Access Control 三大认证组件 源码分析 一.认证组件 自定义认证类 使用: 二.权限组件 自定义权限类 三.频率组件 ...
- 用javafx webview 打造自己的浏览器
背景 项目需要做一个客户端的壳,内置浏览器,访问指定 的url 采用技术 java 1.8 开始吧! java环境配置略 hello world import javafx.application.A ...