Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
const int mod = 1e9 + 7;
long long dp[N];
long long solve(long long rem){
    if(rem == 0) return 1;
    long long ans = 0;
    long long &ret = dp[rem];
    if(~ret) return ret;
    if(rem >= 2){
        ans += solve(rem - 2);
        ans %= mod;
        ans += solve(rem - 1);
        ans %= mod;
    }else{
        ans += solve(rem - 1);
        ans %= mod;
    }
    return ret = ans;
    
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin >> t;
    memset(dp , -1 , sizeof dp);
    while(t--){
        int n;
        cin >> n;
        long long ans = solve(n);
        cout << ans << "\n";
    }
    return 0;
}  
Copy
Study Schedule AbduSaber
GNU G++17
71 ms
31.5 MB
Accepted