matrix (DP hetero title, title thinking)

It is God's problem, thanks to the guidance lnc big brother.

Presupposition 1-LL [i] collectively referred to as the left interval, RR [i] -m is a right section

Prefix with the left end section L [i] from 1-i Statistics column, and emerging, R [i] is a right side section ....

F [i] [j] where j represents the current in the i-th column, the left end point and right section (the RR [i]) in the presence of 1 to the number i, the overall scheme represents the current.

So, we divided into several cases

Two are directly transferred

     f [i + 1] [j] = f [i] [j] represents a j i move to the right, but the same program transfer

     f [i + 1] [j + 1] = f [i] [j] * (r [i + 1] -j) show a further option, a new current from r [i + 1] (i.e. the number of the right section) -j transfer

One is aligned with .......

     f[i][j]=f[i][j]*A(i-j-L[i-1],L[i]-L[i-1])

     It indicates that the current operation with the extra step interval is L [i] -L [i-1], it is necessary to fill a

     ijL [i-1] denotes a maximum discharge, and because variable sequence, it is arranged ......

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<vector>
 7 #include<map>
 8 #include<cstring>
 9 #define int long long
10 #define MAXN 3010
11 #define mod 998244353
12 using namespace std;
13 int jie[MAXN],ni[MAXN],ni_c[MAXN];
14 int f[MAXN][MAXN];
15 int A(int x,int y)
16 {
17     if(y==0)return 1;
18    // printf("x=%lld x-y=%lld %lld %lld\n",x,x-y,jie[x],ni_c[x-y]);
19     return jie[x]*ni_c[x-y]%mod;
20 }
21 int n,m;
22 int l[MAXN],r[MAXN];
23 signed main()
24 {
25     scanf("%lld%lld",&n,&m);
26     jie[0]=1; ni[0]=1 ; ni_c [ 0 ] = 1 ;
27      biggest [ 1 ] = 1 ; [ 1 ] = 1 ; ni_c [ 1 ] = 1 ;
28      for ( int i = 2 ; i <= m; ++ i)
     {
 29  30          jie [i] = (['d i- 1 ] *%), MOD;
31 // biggest printf ( "% lld] =% lld \ n", i, I'd [i]); 32          [i] = (mod-mod / i) * [mod%]% mod;
33          ni_c [i] = (ni_c [i- 1 ] * [i])% mod;
34         
     }
35     for(int i=1;i<=n;++i)
36     {
37         int x,y;
38         scanf("%lld%lld",&x,&y);
39         l[x]++;r[y]++;
40     }
41     for(int i=1;i<=m;++i)
42     {
43         l[i]+=l[i-1];
44         r[i]+=r[i-1];
45     }
46     f[1][0]=1;
47     for(int i=1;i<=m;++i)
48     {
49         for(int j=0;j<=r[i];++j)
50         {
51              if(l[i]-l[i-1]>i-j-l[i-1])break;
52              f[i][j]=(f[i][j]*A(i-j-l[i-1],l[i]-l[i-1]))%mod;
53              f[i+1][j]+=f[i][j];
54              f[i+1][j+1]+=f[i][j]*(r[i+1]-j)%mod;
55              //printf("f[%lld][%lld]=%lld\n",i,j,f[i][j]);
56         }
57     }
58     printf("%lld\n",f[m][n]);
59 }
View Code

 

Guess you like

Origin www.cnblogs.com/Wwb123/p/11288184.html
Recommended