fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAX_N = 1005;
  6.  
  7. int n, mod;
  8. int fibonacci[MAX_N], dp[MAX_N];
  9.  
  10. int main() {
  11. ios::sync_with_stdio(false);
  12. cin.tie(0);
  13. cout.tie(0);
  14.  
  15. freopen("LISFIBO.inp", "r", stdin);
  16. freopen("LISFIBO.out", "w", stdout);
  17.  
  18. cin >> n >> mod;
  19.  
  20. fibonacci[1] = 1;
  21. fibonacci[2] = 1;
  22. for (int i = 3; i <= n; ++i) {
  23. fibonacci[i] = (fibonacci[i - 2] + fibonacci[i - 1]) % mod;
  24. }
  25.  
  26. int res = 0;
  27. for (int i = 1; i <= n; ++i) {
  28. dp[i] = 1;
  29. for (int j = 1; j < i; ++j) {
  30. if (fibonacci[j] <= fibonacci[i]) {
  31. dp[i] = max(dp[i], dp[j] + 1);
  32. }
  33. }
  34. res = max(res, dp[i]);
  35. }
  36.  
  37. cout << res << '\n';
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty