链接:

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(组合数)的更多相关文章

  1. 1067 - Combinations

    1067 - Combinations   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Giv ...

  2. Lightoj 1067【逆元模板(求C(N,M))】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...

  3. 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 ...

  4. light oj 1067 费马小定理求逆元

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1067 1067 - Combinations Given n differen ...

  5. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  6. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

  7. lightoj 1060 - nth Permutation(组合数+贪心)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1060 题解:如果是不重复数的这些操作可以用康托展开的逆来求,如果是有重复数字出 ...

  8. lightoj 1095 - Arrange the Numbers(dp+组合数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1095 题解:其实是一道简单的组合数只要推导一下错排就行了.在这里就推导一下错排 ...

  9. lightoj 1226 - One Unit Machine(dp+大组合数去摸)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1226 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...

随机推荐

  1. 微信小程序访问豆瓣电影api400错误解决方法

    最近在跟着demo学习微信小程序,却卡在了第一步请求豆瓣电影api上,折腾了很久,代码如下: wx.request({ url : "https://api.douban.com/v2/mo ...

  2. pt-archiver 归档历史数据及参数详解

    目录 1. 背景 2. 操作步骤 2.1. 确认数据归档条件,此次操作开发按照非主键列 server_time 按时间进行删除并保存,需要转化为主键列条件. 2.2. 由于历史表文件较大,按月归档.删 ...

  3. InfoGan笔记

    InfoGAN: Interpretable Representation Learning by Information Maximizing Generative Adversarial Nets ...

  4. maven 打包错误 Cannot access central in offline mode

    出错的场景是这样的,先是在一台联网的linux机器上下载项目需要的包,linux机器上jdk为1.8 springboot1.5.然后将项目代码和.m2目录拷贝到一台windows机器上,window ...

  5. mysql中sum与if,case when 结合使用

    1.sum与if结合使用 如图:数据表中,count_money 字段可为正,可为负.为正表示收入,负表示支出. 统计总收入,总支出. select sum(if(count_money > 0 ...

  6. [洛谷P5367]【模板】康托展开

    题目大意:给定一个$n$的排列,求它在$n$的全排列中的名次 题解:康托展开,对于一个全排列,第$i$为有$n+1-i$种选择,用变进制数表示,这一位就是$n+1-i$进制.记排列中第$[1,i)$中 ...

  7. gensim快速上手教程

    1 gensim是什么?        gensim是一个Python常用的的自然语言处理开发包, 主要用于词向量训练和加载词向量,以下解释其正确使用姿势. 2 正确使用姿势 from gensim. ...

  8. CacheManager.Core

    GitHub地址:https://github.com/MichaCo/CacheManager CacheManager的优点: 让开发人员的生活更容易处理和配资缓存,即使是非常复杂的缓存方案. C ...

  9. IdentityServer4:发布环境的数字签名证书

    一,jwt的三个组成部件 先来看一个由IdentityServer颁发的一个标准令牌 eyJhbGciOiJSUzI1NiIsImtpZCI6IjBiNTE3ZjIzYWY0OGM4ZjkyZjExM ...

  10. iOS 打包静态库.a文件(真机版 + 虚拟机)

    我们以打包IOS开发中封装的高地地图基础功能包 GDMap为例. 1>我们需要准备好需要打包的GDMap     2>接下来我们开始新建一个工程文件取名GDMap     3>删掉无 ...