[NOIP Simulation Test]: matrix (DP)

Title Description

$ 01 $ matrix determined number satisfying a condition of $ n * m $:
(1) a first row of $ I $ $ 1 ~ l_i $ 1 $ column exactly one $ $ $ 1.
(2) lines of $ I $ $ r_i ~ m $ 1 $ column exactly one $ $ $ 1.
(3) there is at most one 1 $ $ $ $ 1 per column.


Input Format

The first line of two integers $ n, m $. Next, n-$ $ $ 2 $ lines each integers $ l_i, r_i $.


Output Format

A row of integer answer. Modulo of 998,244,353.


Sample

Sample input

2 6
2 4
5 6

Sample Output

12


Data range and tips

For the data of $ 20% $, $ n, m \ leqslant 12 $.
For the data of $ 40% $, $ n, m \ leqslant 50 $.
For the data of $ 70% $, $ n, m \ leqslant 300 $.
For the data of $ 100% $, $ n, m \ leqslant 3000 $, $ 1 \ leqslant l_i <r_i \ leqslant m $.


answer

See this question, we should first think of the number of combinations, and then ......

I started thinking of inclusion and exclusion, just to die over the sample, but suddenly found to be a multi-step inclusion and exclusion, speechless ......

$ 20% $ algorithm:

Search hard enough, do not search wrong, do not remember the return value of metaphysics (which is not something dry on exam 40 points ......) using clock (), recursive functions in clock ().

$ 100% $ algorithm:

$ $ Considering the DP defined bit mean, defined $ dp [i] [j] $ represents the current to the first column $ I $, $ J $ has column discharge scheme of $ 1 $ in the right section.

Let's explain, pay attention to the right side of the interval is not the first $ i $ the right side of the column, but $ r_i $, understand what I spent half an hour ......

The following look at how to move in:

  

Guess you like

Origin www.cnblogs.com/wzc521/p/11286405.html