fork download
  1. #include<iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int t;
  7. cin >> t;
  8. while(t--){
  9. int n;
  10. cin >> n;
  11. vector <pair <int, int> > dp (n+1); //ends with 0,1
  12. dp[0] = make_pair(0,0);
  13. dp[1] = make_pair(1,1);
  14. for(int i=2; i<=n; i++){
  15. int endWith1 = dp[i-1].first;
  16. int endWith0 = dp[i-1].first + dp[i-1].second;
  17. dp[i] = make_pair(endWith0, endWith1);
  18. }
  19. cout << dp[n].first + dp[n].second << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 5308KB
stdin
2
2
3
stdout
3
5