Submission #1109379

#TimeUsernameProblemLanguageResultExecution timeMemory
1109379ASN49KKangaroo (CEOI16_kangaroo)C++14
100 / 100
21 ms14160 KiB
//le privesc ca fiind orientate #include <bits/stdc++.h> #include <sys/time.h> using namespace std; using i64=long long; #define UNUSED -1 #define all(x) x.begin(),x.end() #define pb push_back const int mod=1e9+7,inf=1e9+1; const i64 INF=1e18; int add(int x,int y) { return (x+y)%mod; } void add_self(int& x,int y) { x+=y; if(x>=mod) { x-=mod; } } int prod(int x,int y) { return (1LL*x*y)%mod; } mt19937 rng(69); const int N=2000; int dp[N][N+2]; int signatura(int x) { if(x>=0) { return 1; } return 0; } int main() { int n,start,finish; cin>>n>>start>>finish; start--; finish--; dp[0][1]=1; for(int i=1;i<n;i++) { for(int j=1;j<=i+1;j++) { if(i==start || i==finish) { //adaug ca componenta noua add_self(dp[i][j],dp[i-1][j-1]); //leg cu cv add_self(dp[i][j],dp[i-1][j]); } else { //leg 2 add_self(dp[i][j],prod(dp[i-1][j+1] , j)); //adaug una noua add_self(dp[i][j],prod(dp[i-1][j-1] , j-(i>start)-(i>finish))); } } } cout<<dp[n-1][1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...