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 题解:由于这些任务完成是有先后的所以最后一个完成的肯定是最后一个任务的子 ...
随机推荐
- 喜马拉雅 FM 已购付费音频下载
如何下载在喜马拉雅 FM 中已购买的付费音频.之前想分享自己购买的付费音频给朋友听,碍于喜马拉雅 FM 的音频不能直接导出,所以准备自己搞个下载的小软件. 仅可下载已购买的付费音频.当然,如果你是会员 ...
- 如何在运行时更改JMeter的负载
在某些情况下,能够在不停止测试的情况下更改性能测试产生的负载是有用的或必要的.这可以通过使用Apache JMeter™的恒定吞吐量计时器和Beanshell服务器来完成.在这篇文章中,我们将介绍如何 ...
- 用Python实现扑克牌面试题思路
据说是腾讯的面试题,以下是要求: 一副从1到n的牌,每次从牌堆顶取一张放桌子上,再取一张放牌堆底,直到手中没牌.根据桌上的牌堆顺序,输出原先手中牌堆的顺序数组. 实现思路: 1.首先定义一个2维数组, ...
- linux centos7开机自动启动程序实现
1存放脚本位置 /etc/init.d/ServerManagerCLI.sh 该脚本是自己新建的内容参看2 增加执行权限 chmod +x /etc/rc.d/init.d/ServerManage ...
- Python爬虫b站视频弹幕并生成词云图分析
爬虫:requests,beautifulsoup 词云:wordcloud,jieba 代码加注释: # -*- coding: utf-8 -*- import xlrd#读取excel impo ...
- PowerBuilder中pbm_keydown()和pbm_dwnkey()的区别:
原地址:https://vcoo.cc/blog/463/ PowerBuilder开发中我们经常会用到快捷键的事件编程,在PB中的键盘事件主要用三个:pbm_dwnkey.pbm_keydown.p ...
- Codeforces Round #570 Div. 3
A:暴力从小到大枚举判断. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 10 ...
- go 读取BMP文件头二进制读取
BMP文件头定义: WORD 两个字节 16bit DWORD 四个字节 32bit package main import ( "encoding/binary" "f ...
- Microsoft.AspNet.Identity 自定义使用现有的表—登录实现,aspnet.identity
Microsoft.AspNet.Identity是微软新引入的一种membership框架,也是微软Owin标准的一个实现.Microsoft.AspNet.Identity.EntityFrame ...
- GOF 的23种JAVA常用设计模式总结 01 设计模式的概念分类和功能
1.简介 软件设计模式(Software Design Pattern),又称设计模式,是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.它描述了在软件设计过程中的一些不断重复发生的 ...