HDU 5366 The mook jong
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 5366 The mook jong相关的知识,希望对你有一定的参考价值。
Problem Description
ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks that is 1*1,so it is 1*n。ZJiaQ want to put a mook jong in a brick. because of the hands of the mook jong, the distance of two mook jongs should be equal or more than 2 bricks. Now ZJiaQ want to know how many ways can ZJiaQ put mook jongs legally(at least one mook jong).
Input
There are multiply cases. For each case, there is a single integer n( 1 < = n < = 60)
Output
Print the ways in a single line for each case.
Sample Input
1 2 3 4 5 6
Sample Output
1 2 3 5 8 12
题意
在1*n的院子里铺有1*1的地板,在地板上里放置木人桩,木人桩之间至少相隔2快地板,问至少放置一个木人桩的情况下,可能的情况
题解
不妨设从右往左摆放,在摆放的过程中,显然,对于尚未摆放的部分,只有已摆放的最左的那个木桩有影响,命名为“哨兵桩”,其余已摆放的木桩的摆放情况没有影响
为了便于解释,不妨从左往右编号方格为1-n,这种情况下,哨兵桩位置为i时,接下来只有i-3,i-4……1这些位置可以摆放或者不摆
所以,设a[i]为哨兵桩在i时接下来的摆放方案数,显然a[i]=a[i-3]+a[i-4]+……+a[1]+1;
而最后的答案应该是ans[i]=a[1]+a[2]+……+a[i];
初始时,a[1]=1;a[2]=1;a[3]=1;
#include<stdio.h> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; LL a[70]; LL ans[70]; int main(void) { int n; a[1]=1;a[2]=1;a[3]=1; ans[1]=1;ans[2]=2;ans[3]=3; LL sum=0; for (int i=4;i<=60;++i) { sum+=a[i-3]; a[i]=sum+1; ans[i]=ans[i-1]+a[i]; } while (scanf("%d",&n)!=EOF) { cout<<ans[n]<<endl; } }
以上是关于HDU 5366 The mook jong的主要内容,如果未能解决你的问题,请参考以下文章