uva1073 - Glenbow Museum

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 calledangle 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 integerL (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

  用一个R和O的串能表示出多少个星形图形(在图形内找一个点能看见所有的顶点)。

  这样的图形序列中一定是(N+4)/2个R,(N-4)/2个O,并且O不能相连。这样转化成找长度为N,O不相连、R比O多4个的串有多少个。

  用dp[i][j]表示首尾都是R,一共i个R,j个相连的R(RRR算2个)

这样的串的个数。那么ans[i]=dp[R][3]+2*dp[R][4],R=(i+4)/2。dp[R][3]刚好R比O多4个,dp[R][4]R比O多5个,少一个O,可以把这个O放在串最前或最后,所以是2倍。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<string>
#include<map>
#include<iostream>
#include<algorithm>
#define MAXN 1010
#define MOD 1000000000
using namespace std;
int N;
long long dp[MAXN][6],ans[MAXN];
void init(){
    memset(dp,0,sizeof(dp));
    dp[1][0]=1;
    for(int i=2;i<MAXN;i++)
        for(int j=0;j<5;j++){
            dp[i][j]=dp[i-1][j];
            if(j) dp[i][j]+=dp[i-1][j-1];
        }
    memset(ans,0,sizeof(ans));
    for(int i=4;i<MAXN;i++){
        if(i%2) continue;
        int R=(i+4)/2;
        ans[i]=dp[R][3]+2*dp[R][4];
    }
}
int main(){
    //freopen("in.txt","r",stdin);
    int cas=0;
    init();
    while(scanf("%d",&N),N){
        printf("Case %d: %lld\n",++cas,ans[N]);
    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值