一、题目描述

在这里插入图片描述

二、代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<vector>

using namespace std;
void Robits(vector<vector<int>>& dp)
{
for (int i = 0; i < dp.size(); ++i)
{
for (int j = 0; j < dp[i].size(); ++j)
{
if (i == 0 || j == 0)
{
dp[i][j] = 1;
}
else
{
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
}
}
void print(vector<vector<int>>& dp)
{
for (int i = 0; i < dp.size(); ++i)
{
for (int j = 0; j < dp[i].size(); ++j)
{
cout << dp[i][j] << " ";
}
cout << endl;
}
cout << endl;
}

int main()
{
vector<vector<int>> dp;
dp.resize(4);
for (auto& x : dp)
{
x.resize(6);
}
Robits(dp);
print(dp);
return 0;
}

在这里插入图片描述