Files
python/TangDou/LuoGuBook/P5732.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
529 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int a[N][N];
int n;
int main() {
cin >> n;
//遍历每一行
for (int i = 0; i <= n - 1; i++) {
//遍历每一列
for (int j = 0; j <= i; j++) {
//第一列,最后一列都是1
if (j == 0 || j == i) a[i][j] = 1;
//递推式
else a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}