#70. 递推与递归第四题(NOIP2010)
递推与递归第四题(NOIP2010)
第四题(NOIP2010)
#include<iostream>
using namespace std;
const int NUM = 5;
int r(int n) {
int i;
if (n <= NUM)
return n;
for (i = 1; i <= NUM; i++)
if (r(n - i) < 0)
return i;
return -1;
}
int main() {
int n;
cin >> n;
cout << r(n) << endl;
return 0;
}
- 【判断题】将第4行的
int改为unsigned,答案不会错误。
{{ select(1) }}
- 正确
- 错误
- 【判断题】程序开启O2优化不会返回错误。
{{ select(2) }}
- 正确
- 错误
- 【判断题】如果输入-1,程序会输出-1。
{{ select(3) }}
- 正确
- 错误
- 【判断题】该问题r(n)的值没有规律。
{{ select(4) }}
- 正确
- 错误
- 【选择题】如果输入7,程序会输出( )。
{{ select(5) }}
- -1
- 5
- 1
- 3
- 【选择题】如果输入16,程序会输出( )。
{{ select(6) }}
- 16
- -1
- 4
- 1