Submission #1022359

#TimeUsernameProblemLanguageResultExecution timeMemory
1022359NintsiChkhaidzeTents (JOI18_tents)C++17
100 / 100
150 ms70960 KiB
#include <bits/stdc++.h>
#include <ostream>
#define pb push_back
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define ll long long
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
#define int ll
using namespace std;
 
const int N = 3000 + 5,mod = 1e9 + 7;

int dp[N][N];
signed main() {
  ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
  
  int n,m;
  cin>>n>>m;

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      if (i*j==0) dp[i][j] = 1;

  for (int i = 1; i <= n; i++){
    for (int j = 1; j <= m; j++){
      dp[i][j] = dp[i - 1][j];
      if (j >= 2) dp[i][j] += dp[i - 1][j - 2] * ((j* (j - 1))/2) % mod;
      dp[i][j] %= mod;

      if (i >= 2) dp[i][j] += dp[i - 2][j - 1] * j * (i - 1) % mod; 
      dp[i][j] %= mod;

      dp[i][j] += dp[i - 1][j - 1] * 4 * j % mod;
      dp[i][j] %= mod;;
    }
  }

  cout<<((dp[n][m] - 1)%mod + mod)%mod;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...