CodeForces 3 67E

(109 + 7).

Two ways are considered distinct if there is such j(1 ≤ j ≤ n), that the j-th intervals in two corresponding sequences are not equal.

(109 + 7);
;
][MAX][MAX];
 {
          )
     {
         memset(dp,,         dp[][][]=;
         next=;
                           {
             ;k<=m;k++)
             {
                 next=next^;
                 ;i<=n;i++) ;j<=n;j++)
                 dp[next][i][j]=;
                 ;i<=n;i++) ;j<=i;j++)
                 {
                     dp[next][i+][j]=(dp[next][i+][j]+dp[next^][i][j])%MOD;
                     dp[next][i+][j+]=(dp[next][i+][j+]+dp[next^][i][j])%MOD;
                                          {
                         dp[next][i][j+]=(dp[next][i][j+]+dp[next^][i][j])%MOD;
                         dp[next][i][j]=(dp[next][i][j]+dp[next^][i][j])%MOD;
                     }
                 }
             }
             LL ans=dp[next][n][n]%MOD;
             ;i<=n;i++) ans=(ans*i)%MOD;
             printf(         }
     }
     ;