#P8189. [USACO22FEB] Redistributing Gifts G
[USACO22FEB] Redistributing Gifts G
题目描述
Farmer John has gifts labeled for his cows, also labeled . Each cow has a wishlist, which is a permutation of all gifts such that the cow prefers gifts that appear earlier in the list over gifts that appear later in the list.
FJ was lazy and just assigned gift to cow for all . Now, the cows have gathered amongst themselves and decided to reassign the gifts such that after reassignment, every cow ends up with the same gift as she did originally, or a gift that she prefers over the one she was originally assigned.
There is also an additional constraint: a gift may only be reassigned to a cow if it was originally assigned to a cow of the same type (each cow is either a Holstein or a Guernsey). Given length- breed strings, for each one count the number of reassignments that are consistent with it.
输入格式
The first line contains . The next lines each contain the preference list of a cow. It is guaranteed that each line forms a permutation of .
The next line contains .
The final lines each contain a breed string, each characters long and consisting only of the characters G and H. No breed string occurs more than once.
输出格式
For each breed string, print the number of reassignments that are consistent with it on a new line.
题目大意
题目描述
Farmer John 有 个礼物,编号为 ,准备分给他的 头奶牛,奶牛也编号为 ()。每头奶牛有一个愿望清单,清单是 个礼物的一个排列,奶牛更喜欢清单中靠前的礼物。
FJ 很懒,直接将礼物 分配给了奶牛 。现在,奶牛们聚集在一起,决定重新分配礼物,使得重新分配后,每头奶牛最终得到的礼物要么与原来相同,要么是她更喜欢的礼物。
还有一个额外的限制:一个礼物只能重新分配给与它原主人同类型的奶牛(每头奶牛要么是荷斯坦牛,要么是根西牛)。给定 ()个长度为 的品种字符串,对于每个字符串,计算符合该字符串的重新分配方案的数量。
输入格式
第一行包含 。
接下来的 行,每行包含一头奶牛的愿望清单。保证每行是 的一个排列。
接下来一行包含 。
最后的 行,每行包含一个品种字符串,长度为 ,仅由字符 G
和 H
组成。每个品种字符串只出现一次。
输出格式
对于每个品种字符串,输出一行,表示符合该字符串的重新分配方案的数量。
样例解释
在这个例子中,对于第一个品种字符串,有两种可能的重新分配方案:
- 原始分配:奶牛 得到礼物 ,奶牛 得到礼物 ,奶牛 得到礼物 ,奶牛 得到礼物 。
- 奶牛 得到礼物 ,奶牛 得到礼物 ,奶牛 得到礼物 ,奶牛 得到礼物 。
数据范围
- 对于 ,测试用例 满足 。
- 测试用例 14-18 满足 。
提示
【样例解释】
In this example, for the first breed string, there are two possible reassignments:
- The original assignment: cow receives gift , cow receives gift , cow receives gift , and cow receives gift .
- Cow receives gift , cow receives gift , cow receives gift , and cow receives gift .
【数据范围】
- For , test case T satisfies .
- Test cases 14-18 satisfy .