# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1034275 | toan2602 | Tents (JOI18_tents) | C++14 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int n, m, dp[3005][3005];
int bp(int a, int b) {
int res = 1;
while(b) {
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
void solve() {
cin >> n >> m;
dp[1][1] = 4;
int r2 = bp(2, mod-2);
dp[0][0] = dp[0][1] = dp[1][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if(i==1 && j==1) continue;
dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * j %mod * 4, dp[i][j] %= mod;
if(j>=2)dp[i][j] += (dp[i-1][j-2] * m % mod * (n-1) %mod * r2), dp[i][j] %= mod;
if(i>=2)dp[i][j] += (dp[i-2][j-1] * n % mod * (m-1) %mod * r2), dp[i][j] %= mod;
}
}
cout << dp[n][m];
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen("input.inp","r")){
freopen("input.inp", "r", stdin);
freopen("output.out", "w", stdout);
}
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |