杨辉三角
百度百科【杨辉三角、刘徽、数学归纳法、排列组合】 在线运行C++
1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1
#include <cstdio> #include <vector> // https://cplusplus.com/reference/vector/vector/ using namespace std; enum { N = 10, W = N * 4 }; typedef vector<int> row; void print(int n, const row& r) { int w = n * 4; if (int left = (W - w) / 2) printf("%-*c", left, ' '); for (int i = 0; i < r.size(); i++) printf("%-4d", r[i]); puts(""); } int main() { row r(2, 1); // [1, 1] (x + y) for (int n = 2; n <= N; n++) { print(n, r); // (x + y) * (xx + 2xy + yy) = // xxx + 2xxy + xyy + 1 2 1 0 // xxy + 2xyy + yyy 0 1 2 1 const int m = r.size(); r.push_back(0); row t = r; t.insert(t.begin(), 0); for (int i = 0; i <= m; i++) r[i] += t[i]; } getchar(); return 0; } /* iterator insert (iterator position, const value_type& val); 应为t.insert(t.begin(), 0); t.insert(0, 0); VC6,Warning Level 3: 没警告没错误,一运行就崩 */
令x=y=1,可得2n等于?n个灯,从全亮到全灭,亮=1, 灭=0,有多少种组合?
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
2022-01-14 A Child's History of England.141
2022-01-14 A Child's History of England.140
2022-01-14 A Child's History of England.139
2022-01-14 A Child's History of England.138
2022-01-14 A Child's History of England.137
2022-01-14 A Child's History of England.136
2022-01-14 A Child's History of England.135