Red, green, and blue tiles
Using a combination of black square tiles and oblong tiles chosen from: red tiles measuring two units, green tiles measuring three units, and blue tiles measuring four units, it is possible to tile a row measuring five units in length in exactly fifteen different ways.
How many ways can a row measuring fifty units in length be tiled?
NOTE: This is related to Problem 116.
红色、绿色和蓝色的地砖
使用黑色地砖、长度为2的红色地砖、长度为3的绿色地砖、长度为4的蓝色地砖的组合,一共有恰好15种不同的方式铺满长度为5的一行。
一共有多少种不同的方式铺满长度为50的一行?
注意:这道题和第116题有关。
package projecteuler;
import java.util.Arrays;
import junit.framework.TestCase;
public class Prj117 extends TestCase{
public void testRedGreenAndBlueTilesMixed(){
{
long v = countingNumber(50, new long[]{1,1,2,4}, new int[]{1,2,3,4});
System.out.println(v);
System.out.println(Arrays.toString(s));
}
}
long s[] = null;
long countingNumber(int n, long[] init, int[] min) {
s = new long[n + 1];
for( int i = 0 ; i < init.length; i ++){
s[i] = init[i];
}
for( int i = init.length; i <= n; i ++){
for( int j = 0; j < min.length; j ++){
s[i] += s[i - min[j]];
}
}
return s[n];
}
}