LA4123 Glenbow Museum 递推


Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

[]   [Go Back]   [Status]  

Description

Download as PDF

The famous Glenbow Museum in Calgary is Western Canada's largest museum, with exhibits ranging from art to cultural history to mineralogy. A brand new section is being planned, devoted to brilliant computer programmers just like you. Unfortunately, due to lack of space, the museum is going to have to build a brand new building and relocate into it.

The size and capacity of the new building differ from those of the original building. But the floor plans of both buildings are orthogonal polygons. An orthogonal polygon is a polygon whose internal angles are either 90° or 270°. If 90° angles are denoted as R (Right) and 270° angles are denoted as O (Obtuse) then a string containing only R and O can roughly describe an orthogonal polygon. For example, a rectangle (Figure 1) is the simplest orthogonal polygon and it can be described as RRRR (the angles are listed in counter-clockwise order, starting from any corner). Similarly, a cross-shaped orthogonal polygon (Figure 2) can be described by the sequence RRORRORRORRO, RORRORRORROR, or ORRORRORRORR. These sequences are called angle strings.

\epsfbox{p4123.eps}

Of course, an angle string does not completely specify the shape of a polygon -- it says nothing about the length of the sides. And some angle strings cannot possibly describe a valid orthogonal polygon (RRROR, for example).

To complicate things further, not all orthogonal polygons are acceptable floor plans for the museum. A museum contains many valuable objects, and these objects must be guarded. Due to cost considerations, no floor can have more than one guard. So a floor plan is acceptable only if there is a place within the floor from which one guard can see the entire floor. Similarly, an angle string is acceptable only if it describes at least one acceptable polygon. Note that the cross-shaped polygon in Figure 2 can be guarded by someone standing in the center, so it is acceptable. Thus the angle string RRORRORRORRO is acceptable, even though it also describes other polygons that cannot be properly guarded by a single guard.

Help the designers of the new building determine how many acceptable angle strings there are of a given length.

Input

The input file contains several test cases. Each test case consists of a line containing a positive integer L (1$ \le$L$ \le$1000) , which is the desired length of an angle string. The input will end with a line containing a single zero.

Output

For each test case, print a line containing the test case number (beginning with 1) followed by the number of acceptable angle strings of the given length. Follow the format of the sample output.

Sample Input

4 
6 
0

Sample Output

Case 1: 1 
Case 2: 6

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>

using namespace std;

#define MAXN 1000

long long f[MAXN+5][5][2];
long long a[MAXN+5];
int main()
{
    memset(f,0,sizeof(f));
    //当R数量确定以后O也确定。
    for(int k=0;k<2;k++)
    {
        //f(i,j,k) i个R,其中j对相邻R(最多4对),第一个元素为k,最后一个元素是R
        //f(1,0,1)=1;
        //f(1,0,0)=1;
        //f(1,j,k)=0;
        f[1][0][k]=1;
        for(int i=2;i<=MAXN;i++)
            for(int j=0;j<5;j++)
            {
                //f(i,j,k)=f(i-1,j-1,k)+f(i-1,j,k);
                //f(i-1,j-1,k)后面+OR得到f(i,j,k);
                //f(i-1,j,k)后面加一个R得到f(i,j,k);
                f[i][j][k]=f[i-1][j][k];
                if(j>0)
                    f[i][j][k]+=f[i-1][j-1][k];
            }
    }
    memset(a,0,sizeof(a));
    for(int i=1;i<=MAXN;i++)
    {
        //n<4或者n为奇数则为0,因为90 270内角,这一条件,所以不会有奇数
        if(i<4||i%2==1) continue;
        a[i]=f[(i+4)/2][3][0]+f[(i+4)/2][4][1]+f[(i+4)/2][4][0];
    }
    int n;
    int cs=1;
    while(~scanf("%d",&n)&&n)
        printf("Case %d: %lld\n",cs++,a[n]);

    return 0;
}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值