题目大意:蓝书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. mybatis中一对一关系映射

    一对一关系中普通的配置方式 一.多表连接查询语句: <select id="selectStudentWithAddress" parameterType="int ...

  2. SQL Serve 临时表

    SQL Server 支持临时表.临时表就是那些名称以井号 (#) 开头的表.如果当用户断开连接时没有除去临时表,SQL Server 将自动除去临时表.临时表不存储在当前数据库内,而是存储在系统数据 ...

  3. 使用vue-cli搭建vue项目简单教程

    一直没有时间来写些东西,今天就写写vue脚手架吧,初建一个vue项目. vue是近段时间来特别火的一个mvvm框架,小巧.简单.易学,如果你的前端基础还好的话,学起来挺简单的.官网地址: https: ...

  4. 查看linux的shhd端口号 netstat | grep sshd

    [root@iZ2zef51hufoaycipfxek8Z ~]# [root@iZ2zef51hufoaycipfxek8Z ~]# netstat | grep sshd [root@iZ2zef ...

  5. C语言利用动态数组实现顺序表(不限数据类型)

    实现任意数据类型的顺序表的初始化,插入,删除(按值删除:按位置删除),销毁功能.. 顺序表结构体 实现顺序表结构体的三个要素:(1)数组首地址:(2)数组的大小:(3)当前数组元素的个数. //顺序表 ...

  6. android Serializable 和 Parcelable 区别

      android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable. 一 序列化原因: 1.永久性保存对象,保存对象的字节序列到本地文件中:2.通过 ...

  7. sql自定义日期函数,返回范围内日期和星期数表。

    Create function [dbo].[FUN_GenerateTime] ( @begin_date datetime, -- 起始时间 @end_date datetime -- 结束时间 ...

  8. 101 删除排序数组中的重复数字 II

    原题网址:http://www.lintcode.com/zh-cn/problem/remove-duplicates-from-sorted-array-ii/# 跟进“删除重复数字”: 如果可以 ...

  9. 杂项-公司:SAMSUNG

    ylbtech-杂项-公司:SAMSUNG 三星集团是韩国最大的跨国企业集团,同时也是上市企业全球500强,三星集团包括众多的国际下属企业,旗下子公司有:三星电子.三星物产.三星航空.三星人寿保险等, ...

  10. FormData兼容IE10 360及DWR的异步上传原理

    摘自:https://github.com/henryluki/FormData/blob/master/formdata.js if(!window.FormData) { (function(se ...