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 ...
随机推荐
- thinkphp 命名范围
在应用开发过程中,使用最多的操作还是数据查询操作,凭借ThinkPHP的连贯操作的特性,可以使得查询操作变得更优雅和清晰,命名范围功能则是给模型操作定义了一系列的封装,让你更方便的操作数据. 命名范围 ...
- 「题解」:[AHOI2012] 树屋阶梯
A掉了第一道题然后就去肝第四题,被路过的Larry大神看到了. L:你怎么还没过掉第三题? 我:…… L:快我帮你过掉! 他拉下来我第一题的码,手改了两个参数,半分钟后:AC …… 然后我就理所当然的 ...
- bootStrap-treeview插件
简要教程 bootstrap-treeview是一款效果非常酷的基于bootstrap的jQuery多级列表树插件.该jQuery插件基于Twitter Bootstrap,以简单和优雅的方式来显示一 ...
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- 虚拟机vm安装黑群晖6.2
操作系统选择
- osg::BlendFunc来设置透明度
osg::BlendFunc介绍 混合是什么呢?混合就是把两种颜色混在一起.具体一点,就是把某一像素位置原来的颜色和将要画上去的颜色,通过某种方式混在一起,从而实现特殊的效果. 假设我们需要 ...
- 快速I/O 51node 1406
#include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int,int> ...
- PHP简单实现“相关文章推荐”功能的方法(此方法不是自创)
1, 所用的函数:int similar_text ( string $first, string $second[, float $percent] ) 利用similar_text将这些文章标题同 ...
- [转]C#委托的异步调用
本文将主要通过“同步调用”.“异步调用”.“异步回调”三个示例来讲解在用委托执行同一个“加法类”的时候的的区别和利弊. 首先,通过代码定义一个委托和下面三个示例将要调用的方法: ); //模拟该方法运 ...
- Django WSGI响应过程之WSGIHandler
class WSGIHandler(base.BaseHandler): request_class = WSGIRequest def __init__(self, *args, **kwargs) ...