码迷,mamicode.com
首页 > 其他好文 > 详细

组合数的计算

时间:2019-08-23 13:25:48      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:space   using   col   i++   color   name   style   int   names   

////根据递推式dp[n][m]=dp[n-1][] 
//void cal(){
//    C[0][0]=1;
//    for(int i=1;i<=1000;i++){
//        C[i][0]=C[i][i]=1;
//        for(int j=1;j<=(i>>1);j++){
//            C[i][j]=C[i][i-j]=(C[i-1][j-1]%mod+C[i-1][j]%mod)%mod;
//        }
//    }
//} 
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
int dp[N][N];
void cinin()
{
    for(int i=0;i<=N;i++){
        dp[i][i]=dp[i][0]=1;
    }
    for(int i=1;i<=N;i++)
        for(int j=1;j<=i;j++){
            dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]);
        }
}


int main(){
    cinin();
    int n,m;
    while(cin>>n>>m){
        cout<<dp[n][m]<<endl;
    }
    
    return 0;
}

dp[n][m]指从n个数中挑选m个

组合数的计算

标签:space   using   col   i++   color   name   style   int   names   

原文地址:https://www.cnblogs.com/Accepting/p/11399377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!