#gesp4t24. 2024GESP四级 递推

2024GESP四级 递推

2024GESP四级 递推

2403真题

1.(2403-8)下面C++函数中采用的算法是( )?

int fib(int n)
{
    int i, f[n]={0, 1};
    
    for(int i=2; i<=n; i++)
    	f[i]=f[i-1]+f[i-2];
    
    return f[n];
}

{{ select(1) }}

  • 递推
  • 递归
  • 迭代
  • 循环

2406真题

2.(2406-9)下面关于递推的说法不正确的是( )?{{ select(2) }}

  • 递推表现为自己调用自己
  • 递推是从简单问题出发,一步步的向前发展,最终求得问题。是正向的
  • 递推中,问题的n要求是在计算中确定,不要求计算前就知道n
  • 斐波那契数列可以用递推实现求解

2409真题

3.(2409-9)下面代码采用递推算法来实现整数 的阶乘(n!=n×(n−1)×...×2×1)(n!=n×(n-1)×...×2×1),则横线上应填写( )?

int factorial(int n) {
    int result = 1;
    for (int i = 2; i <= n; i++) {
    	________________________________ // 在此处填入代码
    }
    return result;
}

{{ select(3) }}

  • result *= i;
  • result += i;
  • result *= result;
  • result += result;

2412真题

4.(2412-9)下面代码采用递推算法来计算斐波那契数列f(n)=f(n−1)+f(n−2)f(n)=f(n-1)+f(n-2) ,则横线上应填写( )。?

int fib(int n) {
    if (n == 0 || n == 1)
    	return n;
    
    int f1 = 0;
    int f2 = 1;
    int result = 0;
    for (int i = 2; i <= n; i++) {
    	________________________________ // 在此处填入代码
    }
    return result;
}

{{ select(4) }}

  • result = f1 + f2;
    f1 = f2;
    f2 = result;
    
  • result += f1 + f2;
    f1 = f2;
    f2 = result;	
    
  • result += f1 + f2;
    f2 = result;
    f1 = f2;
    
  • result = f1 + f2;
    f2 = result;
    f1 = f2;