[恢]hdu 1143

2011-12-20 17:54:28

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1143

题意:用2*1的砖铺3*n,有多少种方法。

mark:递推。dp[n] = 4*dp[n-2]-dp[n-4]

代码:

# include <stdio.h>


int dp[35] = {1, 0, 3, 0} ;


int main ()
{
int i, n ;
for (i = 4 ; i<= 30 ; i+= 2)
dp[i] = 4*dp[i-2] - dp[i-4] ;

while (~scanf ("%d", &n))
{
if (n < 0) break ;
printf ("%d\n", dp[n]) ;
}
return 0 ;
}



posted @ 2012-01-06 23:17  Seraph2012  阅读(139)  评论(0编辑  收藏  举报