链接:

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. C语言实现简单的计算器(加、减、乘、除)

    利用运算符做为swich  case 语句条件,实现简单程序的编写;并且对输入的运算做判断,除数为零也需做判断; #include<stdio.h> int add(int a, int ...

  2. Java date日期类型,结束日期减去开始日期求两者时间差,精确到秒

    /** * @Author: * @Description: * @Date: 2019/4/10 19:01 * @Modified By: */ @Slf4j public class DateU ...

  3. Badboy与Jmeter脚本录制

    下载地址: http://www.badboy.com.au         Badboy 是一个强大的工具,旨在帮助测试和开发复杂的动态应用,Badboy 包括一个简单而全面的捕获/回放界面,强大的 ...

  4. golang---获取windows系统相关信息

    package main import ( "fmt" "net" "runtime" "strings" " ...

  5. DBCP数据库连接池初探

    1. 概述 数据库连接是很“宝贵的”,如果每次获取Connection都去创建数据库连接,使用之后就断开,再次使用又重新创建,程序效率是很低的.因为Socket连接的建立很消耗资源. 所以需要数据库连 ...

  6. QSDK与OPENWRT区别

    QSDK与OPENWRT区别 来源 https://www.jianshu.com/p/178ae18b2570 QSDK是一种在openwrt的基础上,加入了高通atheros芯片相关资料的一种环境 ...

  7. springboot笔记06——使用Thymeleaf模板引擎

    前言 Springboot 推荐使用Thymeleaf做视图层.Thymeleaf支持 html 原型,然后在 html 标签里增加额外的属性来达到模板+数据的展示方式.浏览器解释 html 时会忽略 ...

  8. 4_PHP流程控制语句_3_程序跳转和终止语句

    以下为学习孔祥盛主编的<PHP编程基础与实例教程>(第二版)所做的笔记. PHP流程控制共有3种类型:条件控制结构.循环结构以及程序跳转和终止语句. 4.3 程序跳转和终止语句 4.3.1 ...

  9. JS函数的三种方式

    函数,一段能够自动完成某些功能的代码块,函数的出现,既解决了重复使用重一功能的需求,又可以避免代码的臃肿性. 使用函数有两个要求:必须调用后才可以执行;函数名不要和关键字以及系统函数相同; 函数主要有 ...

  10. VS2017 Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock"): Permission denied fatal: Unable to process path .vs/xxxxxx/v15/Server/sqlite3/db.lock

    具体错误信息:Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock") ...