fork(1) download
  1. // to fill a 3xn board with 2x1 dominoes.
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int countWays(int n)
  6. {
  7. int A[n + 1], B[n + 1];
  8. A[2] = 3, A[1] = 0, B[2] = 1, B[1] = 0;
  9. for (int i = 3; i <= n; i++) {
  10. B[i] = A[i-2] + B[i-2];
  11. A[i] = A[i - 2] + 2 * B[i];
  12.  
  13. }
  14.  
  15. return A[n];
  16. }
  17.  
  18. int main()
  19. {
  20. int n = 4;
  21. cout << countWays(n);
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
11