fork(1) download
  1. #include <stdio.h>
  2.  
  3. long long int f[100][2];
  4.  
  5. // c로 끝나는 n자리 이친수의 개수
  6. long long int op(int n, int c)
  7. {
  8. if (f[n][c] > -1) return f[n][c];
  9. if (c == 0)
  10. {
  11. f[n][0] = op(n - 1, 1) + op(n - 1, 0);
  12. return f[n][0];
  13. }
  14. else if (c == 1)
  15. {
  16. f[n][1] = op(n - 1, 0);
  17. }
  18. }
  19.  
  20. int main()
  21. {
  22. long long int N;
  23. scanf("%lld", &N);
  24. for (int i = 2; i <= N; i++)
  25. {
  26. for (int j = 0; j < 2; j++)
  27. f[i][j] = -1;
  28. }
  29. f[1][1] = 1;
  30. f[1][0] = 0;
  31. printf("%lld\n", op(N, 0) + op(N, 1));
  32. return 0;
  33. }
Success #stdin #stdout 0s 4300KB
stdin
3
stdout
-1