No ideas, like pressed to death did not tune out ...... Tucao about this topic well clear description of ah lot of people have misunderstood the question ......
answer:
Really quite immortal, because there is a limit up to put one in each column, so consider columns dp, set f [i] [j] represents Before considering i listed in [1, i] in the right interval having j 1, the initial state f [0] [0] = 1; Note: the following represents the right interval [r [u], m] ;
Record l, r prefix and sl, sr, but the meaning of these two arrays are not the same, sl [i] i represents the column before how many rows left interval has ended, sr [i] is represented before i row how many rows are the right interval has begun.
Transfer: First, consider only the i-th column, the right section enumerate the number of J 1, 1 if the i th column and hold, then $ f [i] [j] + = f [i-1] [j] $, if an i-th column discharge, it is not considered the front row i-1 should be sound, $ f [i] [j ] + = f [i-1] [j-1] * (sr [i] -j + 1) $ herein explain the $ SR [i] -j + $ 1 , you can put the front section comprises a right SR i th column [i] in row 1, and the front row i-1 has put a $ j-1 $ 1 occupied $ (j-1) $ line, the i-th column can be put to a number of rows $ (sr [i] - ( j-1)) $, obtained by the multiplication counting principle above formula. But we do not consider this is the case before i left column interval: the same enumeration of the right interval to put the k 1, then there is (sl [i] -sl [i -1]) a left end of the range of the i-th row, so At this point there (sl [i] -sl [i -1]) a 1 must be placed, while ik-sl [i-1] can put a location, so to take A_ {$ IK-SL [I- . 1] } ^ { SL [I] -sl [-I. 1] } $, if not legal will become negative. Finally, f [m] [n] is the final answer.
1 #include<iostream> 2 #include<cstdio> 3 #define LL long long 4 #define int LL 5 #define mod 998244353 6 #define MAXN 3010 7 using namespace std; 8 int n,m,l[MAXN],r[MAXN]; 9 int sl[MAXN],sr[MAXN],f[MAXN][MAXN]; 10 signed main() 11 { 12 cin>>n>>m; 13 for(int i=1;i<=n;i++)cin>>l[i]>>r[i],sl[l[i]]++,sr[r[i]]++; 14 for(int i=1;i<=m;i++)sl[i]+=sl[i-1],sr[i]+=sr[i-1]; 15 f[0][0]=1; 16 for(int i=1;i<=m;i++) 17 { 18 f[i][0]=f[i-1][0]; 19 for(int j=1;j<=i;j++) 20 f[i][j]=(f[i-1][j]+f[i-1][j-1]*(sr[i]-j+1)%mod)%mod; 21 for(int k=0;k<=i;k++) 22 for(int j=sl[i-1];j<sl[i];j++) 23 f[i][k]=f[i][k]*(i-k-j)%mod; 24 } 25 printf("%lld\n",f[m][n]); 26 }