首页 > 代码库 > Coderforces 509A

Coderforces 509A

 

背景:esay

学习:

1.杨辉三角与组合数与二项式公式:

          a:二项式公式:技术分享,组合数是二项式公式的系数,而杨辉三角是组合数的图形表示。

         b:组合数公式:技术分享                                                                                                                                                                                                                                                                                                   组合数恒等式:C(n,m)=C(n-1,m-1)+C(n,m)

 2.我的代码是递推法:

#include<stdio.h>
#include<string.h>

int main(void){<span id="transmark"></span>
    int n,map[10][10];
    while(~scanf("%d",&n)){
        memset(map,0,sizeof(map));
        for(int i=0;i < n;i++){
            map[0][i]=1;
            map[i][0]=1;
        }
        for(int i=1;i < n;i++){
            for(int j=1;j < n;j++){
                map[i][j]=map[i-1][j]+map[i][j-1];
            }
        }
        printf("%d\n",map[n-1][n-1]);
    }
    return 0;
}
也可以用递归实现:


                                                                                                                                                                                                                              

Coderforces 509A