> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/advanced-math/pascal-triangle.md).

# 杨辉三角

### 定义

每行两端为 1，其余数等于上一行相邻两数之和：

```
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
```

### 与组合数的关系

第 n 行第 k 个数正好是组合数 C(n-1, k-1)（从 0 开始编号）。

### 实现

```cpp
const int N = 30;
long long c[N][N];
for (int i = 0; i < N; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++)
        c[i][j] = c[i-1][j-1] + c[i-1][j];
}
cout << c[n][k];   // 即 C(n, k)
```

### 应用

* 小范围组合数打表 O(n²)
* 二项式 (a+b)^n 的系数
* 路径计数问题


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/advanced-math/pascal-triangle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
