LA4123 Glenhow Museum
题目大意:蓝书P115
不愧是WF的题
不难发现R的个数为L/2 + 2,O的个数为L/2 - 2
三种做法,第一种比较麻烦,dp[i][j][k][l]表示i个R,j个O,第一个元素是(k)R,最后一个元素是(l)R
不难发现i - j > 5无意义,线性复杂度
第二种,压缩状态。
不难发现求得的序列就是一个RORORORO序列或者ROROROR序列中间加若干R组成罢了,不妨设开头结尾都是R,记录中间差了多少个R
dp[i][j]表示有i个R,开头结尾都是R,有k个连续的R(对连续的定义式:ROROROR...OR中插入k个R叫做有k个连续)的方案数
dp[i][j] = dp[i-1][j] + dp[i][j-1]
考虑如何从i-1个R的序列获得i个R的序列:在末尾加R,或者在末尾加OR(为什么非要在后面加?在中间加不行吗?当然行啊!你当然可以定义为“在L/2出加”“在第6个位置加”,前提是位置确定才行)
答案的开头结尾有三种:R,R R,O O,R后两种等价,不妨设R的个数为x
R,R:dp[x][3] 此时R与O一样多
RO:dp[x][4] 此时R比O多一个,最后多一个O,相当于一RO结尾
OR:dp[x][4] 此时R比O多一个,最后多一个O,相当于一RO结尾
ans = dp[x][3] + 2 * dp[x][4]
好题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(long long &a, long long &b)
{
long long tmp = a;a = b;b = tmp;
}
inline void read(long long &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const long long INF = 0x3f3f3f3f;
const long long MAXN = ; long long t,n,dp[MAXN][]; int main()
{
dp[][] = ;
for(register long long i = ;i <= ;++ i)
for(register long long j = ;j < ;++ j)
if(j) dp[i][j] = dp[i - ][j] + dp[i - ][j - ];
else dp[i][j] = dp[i - ][j];
while(scanf("%d", &n) != EOF && n)
{
++ t;
long long tmp = n/ + ;
printf("Case %lld: ", t);
if(n & ) printf("0\n");
else printf("%lld\n", dp[tmp][] + * dp[tmp][]);
}
return ;
}
LA4123
LA4123 Glenhow Museum的更多相关文章
- 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 ...
- 每日英语:Nanjing's New Sifang Art Museum Illustrates China's Cultural Boom
In a forest on the outskirts of this former Chinese capital, 58-year-old real-estate developer Lu Ju ...
- CodeForces 731A Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- McNay Art Museum【McNay艺术博物馆】
McNay Art Museum When I was 17, I read a magazine artice about a museum called the McNay, once the h ...
随机推荐
- 手把手教你 GitLab 的安装及使用(转)
深山田 关注 2018.01.30 22:58 字数 1696 阅读 15559评论 2喜欢 15 前言 新入职公司,发现公司还在使用落后生产工具 svn,由于重度使用过 svn 和 git ,知道这 ...
- HDU 1147 /// 判断两线段相交
题目大意: 给定n条线段的端点 依次放上n条线段 判断最后在最上面(不被覆盖)的线段有哪些 到当前线段后 直接与之前保存的未被覆盖的线段判断是否相交就可以了 #include <cstdio&g ...
- DES加密算法-C语言
头文件:DES.h #ifndef DES_hpp #define DES_hpp #include <stdio.h> #include <memory.h> #includ ...
- raw_input和sys.stdin.readline()
sys.stdin.readline( )会将标准输入全部获取,包括末尾的'\n',因此用len计算长度时是把换行符'\n'算进去了的; raw_input( )获取输入时返回的结果是不包含末尾的换行 ...
- visual studio 2017--括号自动补全
---恢复内容开始--- 平常在visual studio中编写C++代码,一般括号之类的都是自动补全的,最近想用来编写Python,发现括号不能补全了,很不适应. Python编写时好像括号好像默认 ...
- Mybatis-generator/通用Mapper/Mybatis-Plus对比
mybatis-plus-boot-starter和mybatis-spring-boot-starter冲突导致MapperScan失效问题还没有解决,只能不用mybatis-plus-boot-s ...
- OpenGL键盘交互响应事件
GLUT允许我们编写程序,在里面加入键盘输入控制,包括了普通键,和其他特殊键(如F1,UP).在这一章里我们将学习如何去检测哪个键被按下,可以从GLUT里得到些什么信息,和如何处理键盘输入. 处理 ...
- PostgreSQL问题解决--连接数过多
I am trying to connect to a Postgresql database, I am getting the following Error: Error:org.postgre ...
- Redis系列一之《Redis设计与实践》整体观感
笔者别的Redis方面的书没有读过,读完这一本,力荐,作者黄建宏,对Redis不太熟悉的,但是对编程稍微有些基础的,全部 读下来应该无压力.作者的编写和讲解非常详细,覆盖的面基本上都讲到,之前一直都是 ...
- jQuery实现textarea高度根据内容自适应
//jQuery实现textarea高度根据内容自适应 $.fn.extend({ txtaAutoHeight: function () { return this.each(function () ...