当前位置:编程学习 > C/C++ >>

(组合数学3.1.2.2)POJ 1306 Combinations(c[i][j] = c[i-1][j] + c[i-1][j-1]的实现)

 
/* 
 * POJ_1306.cpp 
 * 
 *  Created on: 2013年10月8日 
 *      Author: Administrator 
 */  
  
#include <iostream>  
#include <cstdio>  
  
using namespace std;  
  
unsigned int c[110][110];  
  
void work(){  
    int i,j;  
    for(i = 0 ; i < 102 ; ++i){  
        c[i][0] = 1;  
    }  
  
    for(i = 1 ; i < 102 ; i++){  
        for(j = 1 ; j < 102 ; ++j){  
            c[i][j] = c[i-1][j-1] + c[i-1][j];  
        }  
    }  
}  
  
int main(){  
    work();  
  
    int n,m;  
    while(scanf("%d%d",&n,&m)!=EOF,n){  
        printf("%d things taken %d at a time is %d exactly.\n",n,m,c[n][m]);  
    }  
}  

 


补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,