我是靠谱客的博主 时尚寒风,这篇文章主要介绍牛客网考研机试题集合:杨辉三角形,现在分享给大家,希望可以做个参考。

考点:组合数

C_{n}^{m}=C_{n-1}^{m}+C_{n-1}^{m-1}    即 fun(n,m)

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<bits/stdc++.h> using namespace std; const int MAXSIZE=1001; int fun(int n,int m); int main() { int n; while(cin>>n) { int i,j; for(i=1; i<n; i++) { for(j=0; j<i; j++) { cout<<fun(i,j)<<" "; } cout<<fun(i,i)<<endl; } } return 0; } int fun(int n,int m) { if(m==0||n==m) { return 1; } return fun(n-1,m-1)+fun(n-1,m); }

 

最后

以上就是时尚寒风最近收集整理的关于牛客网考研机试题集合:杨辉三角形的全部内容,更多相关牛客网考研机试题集合内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部