共48道题,当前是第13

初赛真题

01 #include<iostream>
02 using namespace std;
03 
04 int equationCount(int n, int m) {
05     if (n == 1 || m == 1)
06         return 1;
07     else if (n < m)
08         return equationCount(n, n);
09     else if (n == m)
10         return 1 + equationCount(n, n - 1);
11     else
12         return equationCount(n, m - 1) + equationCount(n - m, m);
13 }
14 int main() {
15     int n;
16     cin >> n;
17     cout << equationCount(n, n) << endl;
18     return 0;
19 }

1. A。
2. B。
3. A。
4. B。
5. D。
6. A。

使用递归求解 $n$ 个苹果放 $n$ 个盘子,可以有盘子不放苹果的方案数。

Question

1. 输入的 n 必须为正整数。( )

2. 把第 9 行的 else if(n==m) 和第 10 行的 return 1 + equationCount(n, n-1); 去掉,不影响程序运行结果。( )

3. 把第 17 行 cout << equationCount(n, n) << endl; 的 n, n 改成 n, n + 1 不影响程序运行结果。()

4. 把第 7 行的 else if(n < m) 和第 8 行的 return equationCount(n, n); 去掉,不影响程序运行结果。( )

5. 该算法的时间复杂度为()。

6. 输入 7 的输出结果为( )A