LightOJ - 1067 - Combinations(组合数)
链接:
https://vjudge.net/problem/LightOJ-1067
题意:
Given n different objects, you want to take k of them. How many ways to can do it?
For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways.
Take 1, 2
Take 1, 3
Take 1, 4
Take 2, 3
Take 2, 4
Take 3, 4
思路:
组合数。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e6+3;
int n, k;
int P[MAXN];
LL PowMod(int a, int b)
{
LL res = 1;
while(b)
{
if (b&1)
res = (1LL*res*a)%MOD;
a = (1LL*a*a)%MOD;
b >>= 1;
}
return res;
}
void Init()
{
P[1] = 1;
for (int i = 2;i < MAXN;i++)
P[i] = 1LL*i*P[i-1]%MOD;
}
int main()
{
Init();
int cnt = 0;
int t;
scanf("%d", &t);
while(t--)
{
printf("Case %d:", ++cnt);
scanf("%d%d", &n, &k);
if (k == 0 || n == k)
{
puts(" 1");
continue;
}
int tmp = 1LL*P[k]*P[n-k]%MOD;
tmp = PowMod(tmp, MOD-2);
printf(" %lld\n", 1LL*P[n]*tmp%MOD);
}
return 0;
}
LightOJ - 1067 - Combinations(组合数)的更多相关文章
- 1067 - Combinations
1067 - Combinations PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Giv ...
- Lightoj 1067【逆元模板(求C(N,M))】
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...
- Light OJ 1067 Combinations (乘法逆元)
Description Given n different objects, you want to take k of them. How many ways to can do it? For e ...
- light oj 1067 费马小定理求逆元
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1067 1067 - Combinations Given n differen ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- LightOJ - 1246 Colorful Board(DP+组合数)
http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...
- lightoj 1060 - nth Permutation(组合数+贪心)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1060 题解:如果是不重复数的这些操作可以用康托展开的逆来求,如果是有重复数字出 ...
- lightoj 1095 - Arrange the Numbers(dp+组合数)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1095 题解:其实是一道简单的组合数只要推导一下错排就行了.在这里就推导一下错排 ...
- lightoj 1226 - One Unit Machine(dp+大组合数去摸)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1226 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...
随机推荐
- Tomcat logs文件夹下不同文件的意义
tomcat每次启动时,自动在logs目录下生产以下日志文件,按照日期自动备份 localhost.2016-07-05.txt //经常用到的文件之一 ,程序异常没有被捕获的时候抛出的地 ...
- STL源码剖析——序列式容器#2 List
list就是链表的实现,链表是什么,我就不再解释了.list的好处就是每次插入或删除一个元素,都是常数的时空复杂度.但遍历或访问就需要O(n)的时间. List本身其实不难理解,难点在于某些功能函数的 ...
- python三大器之装饰器的练习
装饰器 加载顺序从下至上 执行顺序从上至下 ''' 多层装饰器 ''' def deco1(func): #func=deco2 def wrapper1(*args, **kwargs): '''t ...
- python 之 Django框架(Django框架简介、视图装饰器、request对象、Response对象)
12.33 Django框架简介: MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器( ...
- foreach引用坑
先看下面代码 $arr1 = [1, 2]; foreach($arr1 as $key => $value) { $value = $value + 1; } var_dump($key, $ ...
- warning: LF will be replaced by CRLF in application.yml. The file will have its origina解决方法
环境: windows提交时报错如图所示: 原因是存在符号转义问题 windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示,解决办法: git con ...
- CF778D Parquet Re-laying 构造
传送门 如果\(2 \not\mid M\),就把两个图折一下,把\(N\ M\)互换,这样就可以保证\(2 \mid M\). 因为操作可逆,所以我们可以选择一个中间状态,把起始和终点状态都变成这个 ...
- 服务端技术选型与考虑(go)
- AssemblyVersion、AssemblyFileVersion、AssemblyInformationalVersion 区别
AssemblyVersion: 几乎保留在.NET内部,AssemblyFileVersion: 就是Windows所见.如果您转到位于目录中的程序集的属性并切换到版本选项卡, 映射到“文件版本”A ...
- HTTPDNS
传统 DNS 缺点 1.域名缓存问题 它可以在本地做一个缓存,也就是说,不是每一个请求,它都会去访问权威 DNS 服务器,而是访问过一次就把结果缓存到自己本地,当其他人来问的时候,直接就返回这 ...