杨辉三角(pascal's triangle)
程序员文章站
2022-06-06 22:20:11
...
输入行数,输出对应的杨辉三角
本题所用:
C(n,0)=1
C(n,k)=C(n,k-1)*(n-k+1)/k
运行结果如下:
//输入行数,输出对应的杨辉三角
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
vector<int> v(i + 1);
v[0] = 1;
cout << v[0] << " ";
for (int j = 1; j <= i; j++) {
v[j] = v[j - 1] * (i - j + 1) / j;
cout << v[j]<<" ";
}
cout << endl;
}
return EXIT_FAILURE;
}
附常用排列组合公式:
二项式定理(binomial theorem)
上一篇: 杨辉三角
下一篇: atcoder:Tokio Marine & Nichido Fire Insurance Programming Contest 2020:E - O(rand)(位运算+二项式反演)
推荐阅读
-
POJ 2704 Pascal's Travels G++ dfs记忆化搜索
-
Leetcode No.119 Pascal's Triangle II(c++实现)
-
杨辉三角(pascal's triangle)
-
LeetCode-119. Pascal's Triangle II
-
119. Pascal's Triangle II [杨辉三角形2]
-
119. Pascal's Triangle II
-
leetcode -- 119. Pascal's Triangle II
-
2018.05.03 leetcode #119. Pascal's Triangle II
-
【leetcode】119. Pascal's Triangle II
-
LeetCode 119. Pascal's Triangle II