Created
February 26, 2013 01:25
-
-
Save daifu/5034982 to your computer and use it in GitHub Desktop.
Determine in how many ways can a 3xN rectangle be completely tiled with 2x1 dominoes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public int triTiling() { | |
| if (n == 0) { | |
| return 1; | |
| } | |
| int[] f = new int[n]; | |
| int[] g = new int[n]; | |
| f[0] = 1; | |
| f[1] = 0; | |
| g[1] = 1; | |
| g[0] = 0; | |
| for (int i = 2; i < n; i++) { | |
| f[i] = f[i-2] + g[i-1] + g[i-1]; | |
| System.out.println(i + " : " + f[i]); | |
| g[i] = f[i-1] + g[i-2]; | |
| } | |
| return f[i]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment