CF979E.Kuro and Topological Parity
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.
The paper is divided into n pieces enumerated from 1 to n. Shiro has painted some pieces with some color. Specifically, the i-th piece has color ci where ci=0 defines black color, ci=1 defines white color and ci=−1 means that the piece hasn't been colored yet.
The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color (0 or 1) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, [1→0→1→0], [0→1→0→1], [1], [0] are valid paths and will be counted. You can only travel from piece x to piece y if and only if there is an arrow from x to y.
But Kuro is not fun yet. He loves parity. Let's call his favorite parity p where p=0 stands for "even" and p=1 stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of p.
It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo 109+7.
Kuro 最近赢得了“史上最聪明的猫”大赛。三位好友决定前往 Katie 家中庆祝 Kuro 的夺冠。享用完丰盛的晚餐后,他们稍作休息,接着开始玩游戏。
Kuro 向 Katie 挑战:仅使用一张白纸、一支铅笔、一把剪刀以及大量箭头(你可以假设有无穷多个箭头),设计一个游戏。Katie 立刻想出了名为“拓扑奇偶性”(Topological Parity)的游戏。
这张纸被划分为 n 个编号为 1 到 n 的区域。Shiro 已用某种颜色涂染了其中一些区域。具体而言,第 i 个区域的颜色为 ci,其中 ci=0 表示黑色,ci=1 表示白色,而 ci=−1 表示该区域尚未着色。
游戏规则很简单:玩家需在若干对互异的区域之间添加一些箭头,使得对每个箭头,其起点区域的编号严格小于终点区域的编号。此外,任意两个不同区域之间至多只能连接一条箭头。之后,玩家需为所有未着色的区域选定颜色(0 或 1)。一种合法的布箭与着色方案的得分,定义为所有颜色交替的区域路径的数量。例如,[1→0→1→0]、[0→1→0→1]、[1]、[0] 均为合法路径,均被计入得分。注意:仅当存在从区域 x 指向区域 y 的箭头时,才允许从 x 走到 y。
但 Kuro 还不满足——他钟爱奇偶性。设他最钟爱的奇偶性为 p,其中 p=0 表示“偶数”,p=1 表示“奇数”。他希望以某种方式布箭并着色,使得最终得分的奇偶性恰好为 p。
看起来满足 Kuro 要求的方案数量会非常多。他想统计这些方案的总数,但这个数可能极其庞大。请帮助他解决这个问题,输出结果对 109+7 取模后的值。
输入格式
The first line contains two integers n and p (1≤n≤50, 0≤p≤1) — the number of pieces and Kuro's wanted parity.
The second line contains n integers c1,c2,...,cn (−1≤ci≤1) — the colors of the pieces.
第一行包含两个整数 n 和 p(1≤n≤50,0≤p≤1)—— 分别表示棋子的数量以及 Kuro 所期望的奇偶性。
第二行包含 n 个整数 c1,c2,...,cn(−1≤ci≤1)—— 表示各棋子的颜色。
输出格式
Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of p.
输出一个整数——即放置箭头并选择颜色的方式数,使得颜色交替的有效路径数量的奇偶性为 p。
输入输出样例
输入#1
3 1 -1 0 1
输出#1
6
输入#2
2 1 1 0
输出#2
1
输入#3
1 1 -1
输出#3
2
说明/提示
In the first example, there are 6 ways to color the pieces and add the arrows, as are shown in the figure below. The scores are 3,3,5 for the first row and 5,3,3 for the second row, both from left to right.

在第一个例子中,共有 6 种方式对棋子进行染色并添加箭头,如下图所示。第一行(从左到右)的得分分别为 3,3,5,第二行(从左到右)的得分分别为 5,3,3。

输入解题思路,AI测评打分。不知道怎么写?