Submission #1118221

#TimeUsernameProblemLanguageResultExecution timeMemory
1118221vjudge1캥거루 (CEOI16_kangaroo)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld double

const int INF = 1e18;
const int mod = 1e9 + 7;

signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, s , f;
   cin >> n >> s >> f;
   int dp[n + 1][n + 1];
   for(int i = 1;i <= n;i++)
   {
       for(int j = 1;j <= n;j++) dp[i][j] = 0;
   }
   dp[1][1] = 1;
   int fixed = 0;
   for(int i = 1;i <= n;i++)
   {
       for(int j = 1;j < i;j++)
       {
           fixed += (i == s or i == f);
           if(i == s or i == f)
           {
               dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
               dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
           }
           else
           {
               dp[i][j + 1] = (dp[i][j + 1] + (dp[i - 1][j] * (j + 1 - fixed))) % mod;
               dp[i][j - 1] = (dp[i][j - 1] + (dp[i - 1][j] * (j - 1))) % mod;
           }
       }
   }
   cout << dp[n][1] << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...