This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
int mod = 1e9 + 7;
int func(int n, int m) {
vector<ll> dp1(m+1, 0), dp2(m+1, 0), dp3(m+1, 0);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp3[j] = dp2[j]; //empty
dp3[j] += (1 + dp2[j-1]) * 4 * j; //one, not connected
if (j > 1) dp3[j] += (1 + dp2[j - 2]) * (j * (j-1))/2; //2 in the row
if (i > 0) dp3[j] += (1 + dp1[j-1]) * j * (i-1);//one col, 2 in the col
dp3[j] %= mod;
}
dp1 = dp2;
dp2 = dp3;
}
return dp2[m];
}
int main() {
int n, m;
cin >> n >> m;
cout << func(n, m) << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |