project euler 117

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.

pe117

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的一行。

pe117

一共有多少种不同的方式铺满长度为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];
	}
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值