이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t n, start, ende;
const int mod=1e9+7;
vector<vector<vector<int32_t> > > mem;
int32_t dp(int i, int left, int right){
if(left<0 || right<0) return 0;
if(left>n || right>n) return 0;
int r=(right-left)+1;
if(mem[i][left][r]!=-1) return mem[i][left][r];
if(i==start){
mem[i][left][r]=((dp(i-1, left+1, right)*(left+1))%mod + dp(i-1, left, right-1))%mod;
return mem[i][left][r];
}
else if(i==ende){
mem[i][left][r]=((dp(i-1, left, right+1)*(right + (i==n)))%mod + dp(i-1, left-1, right))%mod;
return mem[i][left][r];
}
else{
int chose2=(((left+1)*(right+(i==n))))%mod;
mem[i][left][r]=((dp(i-1, left+1, right+1)*chose2)%mod+ dp(i-1, left-1, right-1))%mod;
return mem[i][left][r];
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> start >> ende;
if(ende<start) swap(start, ende);
mem.resize(n+1);
vector<vector<int32_t> > p(1, vector<int32_t> (3, -1));
for(int i=n; i>=0; i--){
mem[i]=p;
p.push_back(vector<int32_t> (3, -1));
}
for(int i=0; i<=n; i++){
for(int j=0; j<3; j++){
mem[0][i][j]=0;
}
}
mem[0][0][1]=1;
cout << dp(n, 0, 0) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |