csp2019 Emiya family meal explanations today

moment

As the nest too dishes, it is not so with the help of a solution to a problem had lost this question.
Write this blog to sort out ideas

text

Conveying
's simplify the meaning of problems: there are \ (n-\) OK \ (m \) sequence, selected from the group \ (K \) legal number of programs to be fulfilled:
1. Select up a line
2 is selected from a maximum of \ (\ lfloor \ frac {k} {2 } \ rfloor \) number
, of course, if you choose 0 in a row, the equivalent number is not in this line of election
-election once the contribution of the answer is that you choose is not all product of the number of zeros. For any \ (k \) , as long as there is a legitimate program, you will be able to take.
(I did not want to complicate pair of title)
According to the above requirements, we found \ (K \) the range is \ ([. 1, n-] \) . Moreover, according to claim 2, under the premise of meeting if a program 1, is not legal, the program then there must be one and only one selected from the group beyond the \ (\ lfloor \ frac {k } {2} \ rfloor \ ) number, it is impossible to have two simultaneously selected number exceeds \ (\ lfloor \ frac {k } {2} \ rfloor \) a. We now know that a feature of the program is not legitimate, then we might as well try the total number of programs - the number of illegal solutions to this idea.

Because the total number of programs to meet 1 case - the number 1 and do not meet the legal number of programs = random selection program - does not meet the program number 1 or 2 are not satisfied, so we are going to calculate the number of programs that satisfy Condition 1 are calculated down.

Calculating the total number of programs: Let \ (all [i] [j ] \) represents the former \ (I \) lines, each line up to choose a total chose \ (J \) a plurality of programs, then the \ (All [ I] [J] = All [I-. 1] [J] + \ sum_ {L =. 1} ^ m {All [I-. 1] [J-. 1] \ Times A [I] [L]} \) . A (\ [i] sum) \ denotes \ (I \) over all of the rows and then \ (all [i] [j ] = all [i-1] [j] + all [i-1] [ j-1] \ times sum [ i] \)

We look at how to count illegal scheme. Mentioned above a certain illegitimate program is only one line choose the number exceeds \ (\ lfloor \ frac {k } {2} \ rfloor \) months, so we can enumerate each column. But we do not know \ (k \) . Then we can set up \ (no [i] [j ] [l] \) shows a front \ (i \) line, the column select the \ (j \) months, the other columns chose \ (l \) months. \ (no [i] [j ] [l] = no [i-1] [j] [l] + no [i-1] [j-1] [l] \ times a [i] [j] + no [i-1] [j ] [l-1] \ times (sum [i] -a [i] [j]) \) This can be a \ (j, l \) is determined only \ (K \ ) . Enumeration Column: \ (O (m) \) , enumeration \ (I \) : \ (O (n-) \) , because the number of values is selected from at most \ (n-\) , so enumeration \ (J , l \) are \ (O (n-) \) , overall complexity \ (O (mn ^ 3) \)

It is clearly not enough, need to be optimized. We found that we actually do not need specific \ (k \) , only need to know the current column and other columns can be the difference between the selected number. why? You may wish to set the current column selected number \ (x + j \) months, the other columns selected number \ (x \) months, then the total number of election is \ (2x + j \) months. Then this scheme for \ (k \ in [\ lfloor \ frac {2x} {2} \ rfloor, \ lfloor \ frac {2x + j} {2} \ rfloor] \) is illegal. Where (X \) \ values arbitrarily, it is possible to cover all \ (K \) . So disposed \ (no [i] [j ] \) representing the forward \ (I \) row, multi-column current enumeration selected from other than the column \ (J \) a number of programs.
\ (no [i] [j ] = no [i-1] [j] + no [i-1] [j-1] \ times a [i] [j] + no [i-1] [j + 1] \ times (sum [i
] -a [i] [j]) \) Note that there is a hole: the enumeration to the first \ (i \) time line, up to the current column will be less than the other columns \ (i \) number, so \ (j \) should be from \ (- i \) to start the enumeration, rather than 0. Considering the subscripts can not be negative, so that each index in the code + n.
If this program is not legitimate program, then the corresponding \ (j \) must be greater than zero.
The final answer is \ (sum_ {j = 1} ^ n {all [n] [j]} - \ sum_ {j = 1} ^ n {no [n] [j]} \)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
    char ch=getchar();
    ll x=0;bool f=0;
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<3)+(x<<1)+(ch^48);
        ch=getchar();
    }
    return f?-x:x;
}
const ll mod=998244353;
ll n,m,a[209][2009],sum[109],all[209][2009];
ll no[109][2109];
ll ans;
int main()
{
    n=read();m=read();  
    for(int i=1;i<=n;i++)
     for(int j=1;j<=m;j++)
      a[i][j]=read(),sum[i]=(sum[i]+a[i][j])%mod;//保险起见随时随地模一下
    all[0][0]=1;  
    for(int i=1;i<=n;i++)
        for(int j=0;j<=n;j++)
            all[i][j]=(all[i-1][j]+all[i-1][j-1]*sum[i]%mod+mod)%mod;  
    for(int j=1;j<=n;j++)
     ans=(ans+all[n][j])%mod;
    for(int lie=1;lie<=m;lie++)
    {
        memset(no,0,sizeof(no));
        no[0][n]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=n-i;j<=n+i;j++)
           {
             no[i][j]=(no[i-1][j]+no[i-1][j-1]*a[i][lie]%mod+no[i-1][j+1]*(sum[i]-a[i][lie])%mod+mod)%mod;
           }
        }
        for(int j=n+1;j<=2*n;j++)
         ans=(ans-no[n][j]+mod)%mod;
    }
    cout<<ans;
    return 0;
}

Guess you like

Origin www.cnblogs.com/lcez56jsy/p/12079053.html