2 solutions

  • 0
    @ 2025-4-21 3:55:55
    #include<iostream>
    using namespace std;
    int main(){
        int a=0,b=1;
        int x;
        cin >> x;
        int i=0;
        while(i<x-1){
            int c = a + b;
            a = b;
            b = c;
            i++;
        }
        cout << a << endl;
        return 0;
    }
    
    • 0
      @ 2024-11-24 22:51:29
      #include <stdio.h>
      #include <stdlib.h>
      #define Max_N 100
      int memo[Max_N+1];
      void init_memo(){
          for(int i=0;i<Max_N;i++){
              memo[i]=-1;
          }
      }
      int fib(n){
          if(n==0) return 0;
          if(n==1||n==2) return 1;
          if(memo[n]!=-1){
              return memo[n];
          }
          memo[n]=fib(n-2)+fib(n-1);
          return memo[n];
      }
      int main(void){
          int n;
          init_memo();
          scanf("%d",&n);
          if(n<0){
              return -1;
          }
          printf("%d",fib(n-1));
          return 0;
      }
      
      • 1

      Information

      ID
      216
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      10
      Tags
      # Submissions
      4
      Accepted
      2
      Uploaded By