Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的算法来一个数n,它比上一个数差2,而2能摆出三种情况,这样如果这个2和前面是分开的,这种情况是 f[n-2] * 3,剩下就要考虑不分开的情况,这也是关键。 仔细分析图可以看出每偶数个格都可以摆成不可分割的,这种情况必须是上下有一排全是横放的,也就是只有两种摆法,这就好办了。 f[0] = 1; f[2] = 3; for (int i=4; i < 32; i++) { f[i] = 3 * f[i-2]; int t = i; while (t >= 4) { f[i] += f[i-t] * 2; t -= 2; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator