求组合数 C(n,m)
下面内容转自: http://blog.csdn.net/zengaming/article/details/63681754
一、求解C(n, m)
公式一:
公式二:
公式二可以这么理解,从n个物品中取m个有2种情况:(1)不取第n个物品,于是从前n-1个中取m个; (2)取第n个物品,于是从前n-1个中取m-1; 所以答案是这两种情况的和
二、求解C(n, m)%p,p为大质数
当n,m,p都很大的时候,用公式二肯定不行了,费时间又费内存,这时候要用公式一,问题是取模时怎样可以把除法转化为乘法?
费马小定理: 若p是质数,且a,p互质,那么 a的(p-1)次方除以p的余数恒等于1, 即a^(p-1) ≡ 1 (mod p),所以a^(p-2) ≡ 1/a (mod p)
公式三:
这里求阶乘的时候要一边乘一边取模,求p-2次方的时候要要快速幂
三、求解C(n, m)%p,p为小质数
Lucas定理:n,m是非负整数,p是质数,将n,m写成p进制的形式,即:n=(a[k], a[k-1]...., a[0])p,m=(b[k], b[k-1]..., b[0])p,则
公式四:
公式五:
在对上面公式证明之前,我们先证明一下下面这个公式
公式六:
证明公式六:
证明公式五:
四、范德蒙恒等式
公式七:
证明:
1.
2.可以这么理解:从n+m个球中取k个球,相当于将球分为两部分,分别有n个球和m个球;结果相当于从n个球中取i个的球情况下,从m个球中取k-i个球,i的范围是[0,k]。
求组合数 C(n,m)的更多相关文章
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- N!分解质因子p的个数_快速求组合数C(n,m)
int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- hdu 2519 求组合数
求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...
- 求组合数 C++程序
一 递归求组合数 设函数为void comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...
- HDU 5698——瞬间移动——————【逆元求组合数】
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- 51nod1119(除法取模/费马小定理求组合数)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 题意:中文题诶- 思路:这题数据比较大直接暴力肯定是不 ...
随机推荐
- node Express安装和使用
1:在cmd命令行下执行npm install -g express,安装全局的express 2:进入需要创建项目的目录下执行express nodeExpressProject,创建express ...
- User-Agent 及其构造
url = ... user_agent = ... headers = {'User-Agent' : user_agent} req = requests.request(url=url, hea ...
- PS 滤镜— —Marble 效果
clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread ...
- 【leetcode刷题笔记】Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- 【leetcode刷题笔记】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- 【leetcode刷题笔记】Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- FEC之我见四
接上文,来详细的说明一下FEC前向纠错的具体实现: FEC_matrix是一个比较常用的算法,Vandermonde,范德蒙矩阵是法国数学家范德蒙提出的一种各列为几何级数的矩阵. 范德蒙矩阵的定义: ...
- bzoj1006神奇的国度
OrzCDQ您太强辣 #include<iostream> #include<cstdio> #include<cstdlib> #include<algor ...
- python 爬取腾讯视频评论
import urllib.request import re import urllib.error headers=('user-agent','Mozilla/5.0 (Windows NT 1 ...
- qduoj 218 签到题
Description a坤和大明在一块由n个方块组成的棋盘(1 × n)上做游戏.一开始a坤在棋盘上放了k个矩形并且没有告诉大明具体位置.每个矩形都占a个连续方块(1 × a),任意两个矩形不可重叠 ...