UVa1073 Glenbow Museum
可以把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的更多相关文章
- LA 4123 - Glenbow Museum
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
- LA 4123 (计数 递推) Glenbow Museum
题意: 这种所有边都是垂直或水平的多边形,可以用一个字符串来表示,一个270°的内角记作O,一个90°的内角记作R. 如果多边形内存在一个点,能看到该多边形所有的点,则这个多边形对应的序列是合法的.这 ...
- UVALive 4123 Glenbow Museum (组合数学)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 易得,当n为奇数或者n<3时,答案为0,否则该序列中必定有(n+4)/2个R ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- [codeforces113D]Museum
D. Museum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input ...
- 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 ...
随机推荐
- Linux - 后台运行 ctrl + z , jobs , bg , fg
一.& 最经常被用到 这个用在一个命令的最后,可以把这个命令放到后台执行 二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停三.jobs查看当前有多少在后台运行的命令四.fg ...
- C#基础-数组-ArrayList
数组ArrayList using System.Collections; //表示引入集合的命名空间 数组ArrayList容量本身是不固定的,根据存储的数据动态变化 // 声明一个ArrayLis ...
- Python如何查看变量在内存中的地址
在python中可以用id()函数获取对象的内存地址. 用法: object = 1 + 2 object -- 对象
- FSMC原理通俗解释
所以不用GPIO口直接驱动液晶,是因为这种方法速度太慢,而FSMC是用来外接各种存储芯片的,所以其数据通信速度是比普通GPIO口要快得多的.TFT-LCD 驱动芯片的读写时序和SRAM的差不多,所以就 ...
- poj-2533 longest ordered subsequence(动态规划)
Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- 关于host,nslookup,dig 的安装
host,nslookup,dig依赖bind包,所以先看一下系统有没有bind包 命令如下:rpm -qa |grep bind 如果没有或者版本太低请升级安装 命令是:yum install bi ...
- Java获得字节码对象的三种方式
1.Class 类的forName方法 Class clazz = Class.forName("com.test.Test"); 该方法要注意的是会抛出一个ClassNotFou ...
- 笔记-python-centos环境下安装配置
笔记-python-centos环境下安装配置 1. 准备工作 环境准备 centos6.5 mini,已有python 2.6.6 下载源码包 Python官网下载Gzipped sour ...
- luogu1233 木棍加工
先排个序然后做最长上升子序列就行了. #include <algorithm> #include <iostream> #include <cstdio> usin ...
- tomcat6-输入输出buffer设计
之前写的一个ppt 搬到博客来