Skip to content

Instantly share code, notes, and snippets.

@daifu
Created February 26, 2013 01:25
Show Gist options
  • Select an option

  • Save daifu/5034982 to your computer and use it in GitHub Desktop.

Select an option

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.
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