이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int r, c;
cin >> r >> c;
ll mod = 1000000007LL;
ll prev[c+1][c+1];
for(int i = 0; i<=c; i++){
for(int j = 0; j<=c; j++){
prev[i][j] = 1LL;
}
}
for(int row = r-1; row>=0; row--){
ll cur[c+1][c+1];
for(int x = 0; x<=c; x++){
for(int y = 0; y<=c; y++){
if(x+y>c){
cur[x][y] = 0LL;
continue;
}
//put 2
ll now = 0LL;
if(y>=2){
now += ((ll)(y-1)*(ll)y)/2LL*prev[x][y-2];
now %= mod;
}
//put 1 to pair with above
if(x>=1){
now += x*prev[x-1][y];
now %= mod;
}
//put 1 in one of 3 bad directions
if(y>=1){
now += 3LL*y*prev[x][y-1];
now %= mod;
}
//put 1 in ok direction
if(y>=1){
now += y*prev[x+1][y-1];
now %= mod;
}
now += prev[x][y];
now %= mod;
cur[x][y] = now;
}
}
for(int x = 0; x<=c; x++){
for(int y = 0; y<=c; y++){
prev[x][y] = cur[x][y];
}
}
}
prev[0][c] += mod-1;
prev[0][c] %= mod;
cout << prev[0][c] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |