제출 #671259

#제출 시각아이디문제언어결과실행 시간메모리
671259uylulu캥거루 (CEOI16_kangaroo)C++17
0 / 100
46 ms125644 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],n,a,b; int f(int pos,int comp,bool front,bool back) { if(comp < 0) return 0; if(pos == n + 1) { return comp == 1; } if(dp[pos][comp][front][back] != -1) return dp[pos][comp][front][back]; if(pos == a) { int res = 0; res = (res + f(pos + 1,comp + 1,0,back))%mod; if(!front) { res = (res + f(pos + 1,comp,1,back))%mod; } return dp[pos][comp][front][back] = res; } if(pos == b) { int res = 0; res = (res + f(pos + 1,comp + 1,front,0))%mod; if(!back) { res = (res + f(pos + 1,comp,front,1))%mod; } return dp[pos][comp][front][back] = res; } int res = 0; if(!front && pos < a) { res = (res + f(pos + 1,comp,1,back))%mod; } if(pos < a) { res = (res + f(pos + 1,comp + 1,0,back))%mod; } if(!back && pos < b) { res = (res + f(pos + 1,comp,front,1))%mod; } if(pos < b) { res = (res + f(pos + 1,comp + 1,front,0))%mod; } res = (res + (f(pos + 1,comp + 1,front,back) * (comp - 1))%mod)%mod; res = (res + (f(pos + 1,comp - 1,front,back) * (comp - 1))%mod)%mod; return dp[pos][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; 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...