Submission #671683

#TimeUsernameProblemLanguageResultExecution timeMemory
671683uyluluKangaroo (CEOI16_kangaroo)C++14
100 / 100
173 ms125940 KiB
#include <bits/stdc++.h> using namespace std; #define ld long double #define int long long #define endl "\n" const int N = 2000,mod = 1e9 + 7; int dp[N + 1][N + 1][2][2]; int n,a,b; int f(int curr,int comp,bool front,bool back) { if(curr == n + 1) { return (comp == 1); } if(dp[curr][comp][front][back] != -1) return dp[curr][comp][front][back]; if(curr == a) { int res = 0; if(!front) { res = (res + f(curr + 1,comp,1,back))%mod; res = (res + f(curr + 1,comp + 1,0,back))%mod; } return dp[curr][comp][front][back] = res; } if(curr == b) { int res = 0; if(!back) { res = (res + f(curr + 1,comp + 1,front,0))%mod; res = (res + f(curr + 1,comp,front,1))%mod; } return dp[curr][comp][front][back] = res; } int res = 0; if(comp > 1) { res = (res + (f(curr + 1,comp - 1,front,back) * (comp - 1))%mod)%mod; } res = (res + (f(curr + 1,comp + 1,front,back) * (comp - 1))%mod)%mod; if(curr < a) { if(!front) { res = (res + f(curr + 1,comp + 1,0,back))%mod; res = (res + f(curr + 1,comp,1,back))%mod; } } if(curr < b) { if(!back) { res = (res + f(curr + 1,comp + 1,front,0))%mod; res = (res + f(curr + 1,comp,front,1))%mod; } } return dp[curr][comp][front][back] = res; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); cin>>n>>a>>b; memset(dp,-1,sizeof(dp)); cout<<f(2,1,0,0)<<endl; vector<int> asd; for(int i = 1;i <= n;i++) { asd.push_back(i); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...