可以把R看成顺时针转90°,O看成逆时针转270°

设R有x个,则180*(n-2)=90*x+270*(n-x)

解得R有(n+4)/2个

O有(n-4)/2个

所以n<4或者n是奇数时无解。

确定有解时,可以DP解决。

设f[第i位][R比O多j个(j的范围为-1到5)][首位是不是O][末尾是不是O]=方案数

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL f[][][][];//[位数][R比O多的个数][首O][尾O]
const int bas=;
int n;
int main(){
int i,j,cas=;
while(scanf("%d",&n) && n){
printf("Case %d: ",++cas);
if(n& || n<){printf("0\n");continue;}
memset(f,,sizeof f);
f[][+bas][][]=f[][bas-][][]=;
for(i=;i<=n;i++){
for(j=-;j<=;j++){
f[i][j+bas][][]=f[i-][j-+bas][][]+f[i-][j-+bas][][];
f[i][j+bas][][]=f[i-][j++bas][][];
f[i][j+bas][][]=f[i-][j-+bas][][]+f[i-][j-+bas][][];
f[i][j+bas][][]=f[i-][j++bas][][];
}
}
LL ans=f[n][+bas][][]+f[n][+bas][][]+f[n][+bas][][];
printf("%lld\n",ans);
}
return ;
}

UVa1073 Glenbow Museum的更多相关文章

  1. LA 4123 - Glenbow Museum

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  2. LA 4123 (计数 递推) Glenbow Museum

    题意: 这种所有边都是垂直或水平的多边形,可以用一个字符串来表示,一个270°的内角记作O,一个90°的内角记作R. 如果多边形内存在一个点,能看到该多边形所有的点,则这个多边形对应的序列是合法的.这 ...

  3. UVALive 4123 Glenbow Museum (组合数学)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R ...

  4. UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)

    Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the W ...

  5. Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集

    D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...

  6. Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. A. Night at the Museum Round#376 (Div. 2)

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. [codeforces113D]Museum

    D. Museum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input ...

  9. Codeforces 376A. Night at the Museum

    A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. Bootstrap历练实例:交替的进度条

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  2. TCP/IP协议头部结构体

    TCP/IP协议头部结构体(转) 网络协议结构体定义 // i386 is little_endian. #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN (1) ...

  3. C# 调用腾讯地图WebService API获取距离(一对多)

    官方文档地址:https://lbs.qq.com/webservice_v1/guide-distance.html 代码: /// <summary> /// 获取距离最近的点的经纬度 ...

  4. 如何挂载一个镜像文件(how to mount an image file)

    如何挂载一个镜像文件(how to mount an image file) 08/16/2012master 4 Comments 在使用KVM或Xen虚拟化的情况下,经常需要使用镜像文件(imag ...

  5. bash编程之case语句,函数

    bash脚本编程:之case语句   条件测试: 0: 成功 1-255: 失败   命令: [ expression ] [[ expression ]] test expression   exP ...

  6. cin 和 getline 混用中需要注意的问题

    这段时间在刷题过程中遇到一个cin和getline混合使用中的问题,解决之后记录如下: 先来看一段代码 #include <iostream> #include <string> ...

  7. lavarel 添加自定义辅助函数

    Laravel 提供了很多 辅助函数,有时候我们也需要创建自己的辅助函数. 必须 把所有的『自定义辅助函数』存放于 bootstrap 文件夹中. 并在 bootstrap/app.php 文件的最顶 ...

  8. 【mac】【nginx】开机重启

    homebrew.mxcl.nginx.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...

  9. GoF23种设计模式之行为型模式之备忘录模式

    一.概述         在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象的外部保存这个状态.以便以后可以将该对象恢复到原先保存的状态. 二.适用性 1.当需要保存一个对象在某个时刻的状态( ...

  10. python解析库之 XPath

    1. XPath (XML Path Language) XML路径语言 2. XPath 常用规则: nodename    选取此节点的所有子节点 /                    从当前 ...