可以把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. 使用jquery-validate校验表单

    注意: 表单校验(validation校验[需要下载JQuery-validate插件,而且必须要在引入JQuery插件之后,再引入validate插件/*validate是建立在JQuery之上*/ ...

  2. SQL学习总结笔记

    SQL语句的效率不仅是sql语句的设计还有一些其他的原因比如网络 .是否有视图.是否有索引等等.这里主要描述的是我个人对于sql设计方面优化的一些见解: 首先要说明一下的是数据库SQL解析顺序: (1 ...

  3. ssh整合思想初步 struts2与Spring的整合 struts2-spring-plugin-2.3.4.1.jar下载地址 自动加载Spring中的XML配置文件 Struts2下载地址

    首先需要JAR包 Spring整合Structs2的JAR包 struts2-spring-plugin-2.3.4.1.jar 下载地址 链接: https://pan.baidu.com/s/1o ...

  4. cnpm 莫名奇妙bug 莫名奇妙的痛

    cnpm 莫名奇妙bug 莫名奇妙的痛 最近想搭建react@v16 和 react-router@v4,搭建过程打算用vue脚手架webpack模板那套配置方法(webpack3). 由于我之前安装 ...

  5. 基于matlab的蓝色车牌定位与识别---分割

    接着上面的工作,接下去就该是进行字符分割了.考虑到为了后面的字符识别,因此在这部分需要实现的目标是需要把车牌的边框全部切除,对重新定位的车牌进行垂直方向水平方向调整,保证字符是正的.最后才是字符的分割 ...

  6. Neural Style论文笔记+源码解析

    引言 前面在Ubuntu16.04+GTX1080配置TensorFlow并实现图像风格转换中介绍了TensorFlow的配置过程,以及运用TensorFlow实现图像风格转换,主要是使用了文章A N ...

  7. 【kmp】bzoj3620: 似乎在梦中见过的样子

    考察kmp理解题 Description “Madoka,不要相信 QB!”伴随着 Homura 的失望地喊叫,Madoka 与 QB 签订了契约. 这是 Modoka 的一个噩梦,也同时是上个轮回中 ...

  8. 分割catalina.out 每天生成一个文件

    1. touch xxx(文件名字).sh 2.     vim xxx.sh 写入  ----------------------- #!/bin/sh cd `dirname $0`pwdd=`d ...

  9. python-numpy-pandas

    目录 numpy 模块 创建矩阵方法: 获取矩阵的行列数 切割矩阵 矩阵元素替换 矩阵的合并 通过函数创建矩阵 矩阵的运算 pandas模块 series (一维列表) DataFrame DataF ...

  10. supervisor 安装使用

     简介 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管 ...