题目大意:蓝书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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. [codeforces113D]Museum

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

  6. 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 ...

  7. 每日英语: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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python爬取(自动化)豆瓣电影影评,并存储。

    from selenium import webdriverfrom selenium.webdriver import ActionChainsimport time driver = webdri ...

  2. shell脚本练习05

    ######################################################################### # File Name: -.sh # Author ...

  3. WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

    关于这个异常的问题网上有很多的解决方案. 最为靠谱的有: http://www.cnblogs.com/hjf1223/archive/2007/03/14/674502.html(若因为链接而导致不 ...

  4. node web项目结构

  5. 小程序跳转传参参数值为url时参数丢失

    通过先encodeURIComponent,取到值以后再decodeURIComponent,拼接参数正常传递 A页面 switch: function (e) { var aa = 'UNNZVUf ...

  6. JavaWeb开发购物车设计总结

    一. 实体类设计 图书实体类 public class Book { private String id; private String name; private String author; pr ...

  7. python中遇到的问题:IndentationError: unexpected indent

    在Python中写下列代码的时候,出现错误:IndentationError: unexpected indent 分析:IndentationError是缩进的错误,查看源代码发现names开始的这 ...

  8. Python 的一些方法

    有关 Python 内编写类的各种技巧和方法(构建和初始化.重载操作符.类描述.属性访问控制.自定义序列.反射机制.可调用对象.上下文管理.构建描述符对象.Pickling). 你可以把它当作一个教程 ...

  9. 【JZOJ2288】【BZOJ1898】【luoguP2579】沼泽鳄鱼

    description 潘塔纳尔沼泽地号称世界上最大的一块湿地,它地位于巴西中部马托格罗索州的南部地区.每当雨季来临,这里碧波荡漾.生机盎然,引来不少游客. 为了让游玩更有情趣,人们在池塘的中央建设了 ...

  10. GROUP方法也是连贯操作方法之一

    GROUP方法也是连贯操作方法之一,通常用于结合合计函数,根据一个或多个列对结果集进行分组 . group方法只有一个参数,并且只能使用字符串. 例如,我们都查询结果按照用户id进行分组统计: $th ...