基本思想:
无;
关键点:
无;
#include<iostream> #include<vector> using namespace std; int main() { int n; while (cin >> n) { vector<int>vec; vec.push_back(1); vec.push_back(1); for (int i = 2; i <= n; i++) { for (int j = 0; j < vec.size(); j++) { if (j == 0) cout << vec[j]; else cout << " " << vec[j]; } cout << endl; //进行新的构造; vector<int>v1; v1.push_back(1); for (int j = 0; j < vec.size() - 1; j++) { v1.push_back(vec[j] + vec[j + 1]); } v1.push_back(1); vec = v1; } } }
西北工业大学机试 杨辉三角形 需要二刷 *二刷注意递归的做法
原文:https://www.cnblogs.com/songlinxuan/p/12490262.html