标签:style blog http io ar color os sp for
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2606
题意: 用1*1,2*2,3*3,4*4的正方形填充4*n的矩形, 问有多少种不同填法。
分析: f[i] = f[i - 1] + f[i - 2] * 4 + f[i - 3] * 2 + f[i - 4] * 1 + 对错位的情况(即2*(f[n-3] + f[n-4] + ...f[0]), f[0]初始化为1)
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <vector> #include <set> #include <map> #define LL long long #define mod 19890907 #define inf 0x3f3f3f3f #define N 10010 using namespace std; int f[110]; void init() { f[0]=1;f[1]=1;f[2]=5;f[3]=13; for(int i=4;i<=100;i++) { f[i]=(f[i-4]+f[i-3]*2+f[i-2]*4+f[i-1])%mod; for(int j=3;j<=i;j++)f[i]=(f[i]+2*f[i-j])%mod; } } int main() { int n,t; init(); scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d\n",f[n]); } }
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/lienus/p/4164024.html