#P3240. [HNOI2015] 实验比较
[HNOI2015] 实验比较
Description
Little D was invited to a lab to participate in a subjective experiment related to image quality assessment.
The dataset contains images, numbered to . The experiment is conducted in several rounds. In each round, Little D is asked to look at two randomly selected images, and then, based on his subjective judgment, decide which image is better, or that their qualities are about the same.
We use the symbols “”, “”, and “” to denote comparisons between images and (, are image indices): if within the context and are image indices, then means “the quality of image is better than that of ,” means “the quality of image is worse than that of ,” and means “images and have equal quality.” That is, in such contexts, “”, “”, and “” respectively mean better quality, worse quality, and equal quality; in other contexts, these three symbols retain their usual meanings of less than, greater than, and equal to.
Reasoning rules for image quality comparisons (in the context where and are image indices):
- is equivalent to .
- If and , then .
- If and , then .
- is equivalent to .
- If and , then .
In the experiment, Little D needs to provide a subjective judgment for some image pairs : either , or , or . After the experiment, Little D became interested in some global properties of this locally compared experiment.
Given the subjective experiment data, we define a legal quality sequence of these images as a string of the form “,” which can also be regarded as the set , where are image indices, are pairwise distinct (i.e., no duplicate indices), is either or , and “legal” means that this quality sequence does not conflict with any of the subjective judgments.
For example: the quality sequence conflicts with the subjective judgments “, ” (because in the sequence and , hence , which conflicts with in the judgments; meanwhile conflicts with ), but it does not conflict with the judgments “, .” Therefore, given the judgments “, ,” both and are legal quality sequences, while and are illegal quality sequences.
Since some time has passed since the experiment, Little D has forgotten part of the subjective data. For each image , Little D remembers at most one other image whose quality is not better than . Altogether there are remembered judgments (). The -th judgment involves the pair and is either or , and all are pairwise distinct. Little D decides to use precisely these remembered judgments as all his subjective data.
Now, based on these subjective data, we ask you to help Little D compute how many different legal quality sequences there are for the images. We stipulate: if “” appears in a sequence, then swapping the positions of and results in the same sequence. Therefore: and are the same sequence, and are the same sequence, whereas and are different sequences, and and are different sequences.
As the number of legal quality sequences can be large, you must output the answer modulo .
Input Format
The first line contains two positive integers , the total number of images and the number of judgments that Little D still remembers.
The following lines each contain one judgment, in the form “” or “”.
Output Format
Output a single line containing one positive integer, the number of legal quality sequences modulo .
5 4
1 < 2
1 < 3
2 < 4
1 = 5
5
Hint
There are 5 different legal sequences, as listed below:
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号