组合数学之排列组合
一、排列與組合?
?
?
//組合數(shù)C(n,k) ll C(ll n,ll k) {if(2*k>n) k=n-k;ll s=1;for(ll i=1,j=n; i<=k; i++,j--)s=s*j/i;return s; } //排列數(shù)A(n,r) ll A(ll n,ll r) {ll sum=1;for(ll i =0;i<r;i++){sum=sum*(n-i);}return sum; }二、特殊的排列組合?
三、排列的生成算法
bool next_permutation(iterator start,iterator end)
當當前序列不存在下一個排列時,函數(shù)返回false,否則返回true
用法示例:
#include <iostream> #include <algorithm> using namespace std; int main() { int num[3]={1,2,3}; do { cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<endl; }while(next_permutation(num,num+3)); return 0; }?
?
轉(zhuǎn)載于:https://www.cnblogs.com/dillydally/p/9567678.html
總結(jié)
- 上一篇: Etas标定工具-Incacome.dl
- 下一篇: xdoj 1243 ckj老师爱数学