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;
typedef long long ll;
const int MAXN = 2010;
const int MOD = 1e9 + 7;
ll dp[MAXN][MAXN];
int N,cs,cf;
ll solve(int atual,int comp){
if(comp < 0) return 0;
if(dp[atual][comp] != -1) return dp[atual][comp];
int lcomp = (atual > cs);
int rcomp = (atual > cf);
if(atual == N){
return dp[atual][comp] = (comp == 0);
}
ll total = 0;
if(atual == cs){
total += solve(atual+1,comp);// nova componente
total += solve(atual+1,comp-1)*comp;// conecta a alguma
}
else if(atual == cf){
total += solve(atual+1,comp);// nova componente
total += solve(atual+1,comp-1)*comp;// conecta a alguma
}
else{
total += solve(atual + 1,comp + 1); // nova componente
total += solve(atual+1,comp-1)*(comp)*(lcomp + (comp - 1) + rcomp); // conecta duas
}
return dp[atual][comp] = (total % MOD);
}
int main(){
memset(dp,-1,sizeof(dp));
cin >> N >> cs >> cf;
cout << solve(1,0) << endl;
return 0;
}
# | 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... |