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 <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main(){
int n, cs, cf, cnt = 0;
cin>>n>>cs>>cf;
vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(n + 1, vector<ll>(n + 1, 0)));
dp[0][cf][cs] = 1;
for (int i = 0; i < n; i++){
if (i + 1 != cs && i + 1 != cf){
cnt++;
}
for (int j = 1; j <= n; j++){
for (int k = 1; k <= n; k++){
int nu = i + 1;
if (nu == cs || nu == cf){
dp[i + 1][j][k] = dp[i][j][k];
continue;
}
if (cnt == 1){
dp[i + 1][nu][nu] += dp[i][j][k];
}
else{
ll pos = max(i - 1, 0);
if (cnt != 2){
dp[i + 1][j][k] += (dp[i][j][k] * pos) % mod;
dp[i + 1][j][k] %= mod;
}
if (nu < min(j, cs) || nu > max(j, cs)){
dp[i + 1][nu][k] += dp[i][j][k];
dp[i + 1][nu][k] %= mod;
}
if (nu < min(k, cf) || nu > max(k, cf)){
dp[i + 1][j][nu] += dp[i][j][k];
dp[i + 1][j][nu] %= mod;
}
}
}
}
}
ll ans = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
ans += dp[n][i][j];
ans %= mod;
}
}
cout<<ans;
}
# | 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... |