fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int n;
  6. int dp[100001];
  7.  
  8. int threeones(int n)
  9.  
  10. {
  11.  
  12. if (n == 1) return 2;
  13. if (n == 2) return 4;
  14. if (n == 3) return 7;
  15. if (dp[n] != -1) return dp[n];
  16. return dp[n] = (threeones(n-1) + threeones(n-2) + threeones(n-3)) % 12345;
  17. }
  18.  
  19. int main(void)
  20.  
  21. {
  22. memset(dp,-1,sizeof(dp));
  23. cin>>n;
  24. cout<<threeones(n)<<"\n";
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5536KB
stdin
4
stdout
13