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 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...
随机推荐
- Spring 框架的概述以及Spring中基于XML的IOC配置
Spring 框架的概述以及Spring中基于XML的IOC配置 一.简介 Spring的两大核心:IOC(DI)与AOP,IOC是反转控制,DI依赖注入 特点:轻量级.依赖注入.面向切面编程.容器. ...
- array_walk、array_map、array_filter 的用法
array_walk.array_map.array_filter 和 foreach 都有循环对数组元素进行处理的功能. 一.array_walk 用法 1.循环数组,回调处理(并不修改数组元素的 ...
- 使用PHP开发HR系统(4)
本节我们讲述如何引入页面框架来建立漂亮的主页. ============================================================================ ...
- egit报错:cannot open git-upload-pack
第一次通过eclipse导入github 项目,按照百度步骤进行操作,发现不能连接 github,cannot open git-upload-pack. 报错原因通过 eclipse 日志排查报错 ...
- TJOI2019
TJOI出一堆模板题还玩一堆梗是什么鬼 甲苯先生的字符串(矩阵快速幂) 矩阵快速幂模板题 代码 甲苯先生的滚榜(树状数组.线段树) 最开始想平衡树搞,但是平衡树太难写了 一次答案的查询相当于查询比当前 ...
- 玩转Spring全家桶笔记 02 那些好用的连接池HikariCP
1.前言 简单了解一下来自日本的一个新起之秀连接池---HikariCP github:https://github.com/brettwooldridge/HikariCP 2.HikariCP为什 ...
- wpf 把两个Bitmap 合并为一个
水平合并 /// <summary> /// 将两个Bitmap水平合并为一个 /// </summary> /// <param name="first&qu ...
- vue-cli搭建的项目打包之后报“资源路径错误&资源文件找不到“
此方式vue脚手架是3.0版本,2.0版本见最下面//在项目的根目录下(和package.json文件同级)新建一个文件vue.config.js的文件,将此段代码复制进去.module.export ...
- JavaScript之控制标签内容
function abb(a){ return document.getElementById(a); } console.log(abb('box').innerHTML); 标签.innerHTM ...
- requests模块 简单使用
目录 requests模块 简单使用 Anaconda简单了解 简单了解 requests模块 使用requests模块 爬取搜狗首页源码数据 实现一个简易的网页采集器 解决乱码问题 解决UA检测问题 ...