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 ...
随机推荐
- iOS或Mac开发者应该记住的前缀
- C#MySQL增删改查
首先在项目中添加引用 using MySql.Data.MySqlClient; 连接字符串 private string connString="server=localhost;use ...
- js中实现杨辉三角
实现效果:杨辉三角 即: 提示用户输入要实现的杨辉三角行数: 请输入杨辉三角的行数: 8 代码实现后的效果如下: 1 1.1 1.2.1 1.3.3.1 1.4.6.4.1 1.5.10.10.5.1 ...
- HDU-4848-Such Conquering
这题就是深搜加剪枝,有一个很明显的剪枝,因为题目中给出了一个deadline,所以我们一定要用这个deadline来进行剪枝. 题目的意思是求到达每个点的时间总和,当时把题看错了,卡了好久. 剪枝一: ...
- 201621123080《java程序设计》第六周作业总结
201621123080<java程序设计>第六周作业总结 1. 本周学习总结 2. 书面作业 clone方法 1.1 在test1包中编写Employee类,在test2包中新建一个Te ...
- Oracle 数据库常用SQL语句(1)
一.数据定义语句 CREATE:创建表或其它对象 create database test; //创建test数据库 ),sex )); //创建表 ALTER:修改表或其它对象的结构 )); //为 ...
- java代码导出数据到Excel、js导出数据到Excel(三)
jsp内容忽略,仅写个出发按钮: <button style="width: 100px" onclick="expertExcel()&quo ...
- Linux异常处理体系结构
arm11处理器裸机的异常与中断处理参考: [OK6410裸机程序]异常处理 [OK6410裸机程序]按键中断 另外参考一篇:Linux中断体系结构 在ARM V4及V4T以后的大部分处理器中,中断向 ...
- scanf(),gets(),getchar()
scanf()与gets()区别: scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用gets() ...
- Linux操作系统启动流程
一般来说,所有的操作系统的启动流程基本就是: 总的来说,linux系统启动流程可以简单总结为以下几步:1)开机BIOS自检,加载硬盘.2)读取MBR,进行MBR引导.3)grub引导菜单(Boot L ...