이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3+10;
const int MOD = 1e9+7;
ll dp[N][N], n, m;
// From (N, M) we can:
// 1) do nothing and go to (N-1, M)
// 2) put random tent in N-th row in any direction 4*M * (N-1, M-1)
// 3) put 2 tents in N-th row in M*(M-1)/2 * (N-1, M-2)
// 4) put 2 tents in same column s.t. on is in N-th row in M*(N-1)*(N-2, M-1) ways
ll solve(ll n, ll m) {
if (n <= 0 || m <= 0) return 1;
if (dp[n][m] > 0) return dp[n][m];
ll res=solve(n-1, m);
(res+=4*m*solve(n-1, m-1))%=MOD;
(res+=m*(m-1)/2*solve(n-1, m-2))%=MOD;
(res+=m*(n-1)*solve(n-2, m-1))%=MOD;
return dp[n][m]=res;
}
int main() {
cin>>n>>m;
cout<<solve(n, m)-1<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |