题目名称 | 2881. [USACO Nov12] Balanced Cow Breeds |
---|---|
输入输出 | bbreeds.in/out |
难度等级 | ★☆ |
时间限制 | 1000 ms (1 s) |
内存限制 | 256 MiB |
测试数据 | 16 |
题目来源 | WHZ0325 于2017-12-21加入 |
开放分组 | 全部用户 |
提交状态 | |
分类标签 | |
分享题解 |
通过:2, 提交:2, 通过率:100% | ||||
yuan | 100 | 0.006 s | 0.32 MiB | C++ |
WHZ0325 | 100 | 0.007 s | 0.29 MiB | C++ |
关于 Balanced Cow Breeds 的近10条评论(全部评论) | ||||
---|---|---|---|---|
蒟蒻乘舟将欲行,膜拜神犇HJX。
Ceres
2018-02-06 17:15
5楼
| ||||
蒟蒻乘舟将欲行,膜拜神犇HJX。
WHZ0325
2017-12-22 20:01
4楼
| ||||
回复 @PowerOI : %蛤实验巨佬
胡嘉兴
2017-12-22 19:39
3楼
| ||||
回复 @PowerOI :
66
サイタマ
2017-12-22 18:43
2楼
| ||||
今天做到一道不错的题目,与大家分享一下。
WHZ0325
2017-12-21 22:56
1楼
|
bbreeds.in
输出文件:bbreeds.out
简单对比Farmer John usually brands his cows with a circular mark, but his branding
iron is broken, so he instead must settle for branding each cow with a mark
in the shape of a parenthesis -- (. He has two breeds of cows on his farm:
Holsteins and Guernseys. He brands each of his cows with a
parenthesis-shaped mark. Depending on which direction the cow is facing,
this might look like either a left parenthesis or a right parenthesis.
FJ's N cows are all standing in a row, each facing an arbitrary direction,
so the marks on the cows look like a string of parentheses of length N.
Looking at this lineup, FJ sees a remarkable pattern: if he scans from left
to right through just the Holsteins (in the order they appear in the
sequence), this gives a balanced string of parentheses; moreover, the same
is true for the Guernseys! To see if this is truly a rare event, please
help FJ compute the number of possible ways he could assign breeds to his N
cows so that this property holds.
There are several ways to define what it means for a string of parentheses
to be "balanced". Perhaps the simplest definition is that there must be
the same total number of ('s and )'s, and for any prefix of the string,
there must be at least as many ('s as )'s. For example, the following
strings are all balanced:
()
(())
()(()())
while these are not:
)(
())(
((())))
* Line 1: A string of parentheses of length N (1 <= N <= 1000).
(())
* Line 1: A single integer, specifying the number of ways FJ can
assign breeds to cows so that the Holsteins form a balanced
subsequence of parentheses, and likewise for the Guernseys.
Since the answer might be a very large number, please print
the remainder of this number when divided by 2012 (i.e., print
the number mod 2012). Breed assignments involving only one
breed type are valid.
6
The following breed assignments work:
(())
HHHH
(())
GGGG
(())
HGGH
(())
GHHG
(())
HGHG
(())
GHGH