题目大意:蓝书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. JVM实战

    一.内存溢出 虚拟机栈和本地方法栈溢出:-Xss256k package com.jedis; import java.util.LinkedList; import java.util.List; ...

  2. js字符实体 转义字符串

    HTML字符实体(Character Entities),转义字符串(Escape Sequence) 为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,> ...

  3. Python学习之文件操作(二)

    CSV文件处理 在Python中处理CSV文件可以使用模块csv.有关csv模块的官方资料看这里. 1 读取csv文件 csv.reader(csvfile, dialect='excel', **f ...

  4. loj6244 七选五

    题意:从n个数中选k个数,问有多少种排列与标准k项串恰好有x个位置相同. 标程: #include<cstdio> using namespace std; typedef long lo ...

  5. eigen矩阵操作练习

    // // Created by qian on 19-7-16. // /* 相机位姿用四元数表示 q = [0.35, 0.2, 0.3, 0.1] x,y,z,w * 注意:输入时Quatern ...

  6. System.Web.Mvc.ViewResult.cs

    ylbtech-System.Web.Mvc.ViewResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicK ...

  7. 基于SpringBoot免费开源的微信管家平台,Jeewx-Boot 1.0.3 版本发布

    项目介绍 JeewxBoot 是一款基于SpringBoot的免费微信开发平台.支持微信公众号.小程序官网.微信抽奖活动.Jeewx-Boot实现了微信公众号管理.小程序CMS.微信抽奖活动等基础功能 ...

  8. 2016 CCPC网络选拔赛 部分题解

    HDU 5832 - A water problem 题意:有两颗星球,一年的长度分别为37天和173天.问第n天时它们是否为新年的第一天. 思路:显然  n 同时被37和173整除时,两种历法都在新 ...

  9. fastjson中List和JSONArray的相互转换

    https://blog.csdn.net/xiaofei__/article/details/89571320 (1)List转换为JSONArray List<T> list = ne ...

  10. Django项目: 4.用户登录登出功能

    用户登录登出功能 一.功能需求分析 1. 登录退出功能分析 流程图 功能 登录页面 登录功能 退出功能 二.登录页面 1. 接口设计 接口说明 类目 说明 请求方法 GET url定义 /user/l ...