Submission #44782

#TimeUsernameProblemLanguageResultExecution timeMemory
44782bogdan10bosKangaroo (CEOI16_kangaroo)C++14
100 / 100
24 ms14464 KiB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int dp[2005][2005];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    int N, st, fn;
    scanf("%d%d%d", &N, &st, &fn);

    dp[1][1] = 1;
    int ends = 2;
    if(st == 1 || fn == 1)  ends--;
    for(int i = 2; i <= N; i++)
    {
        if(i == st || i == fn)
        {
            for(int j = 1; j <= i; j++)
                dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
            ends--;
            continue;
        }

        for(int j = 1; j <= i; j++)
        {
            dp[i][j] = 0;
            if(j - 2 + ends >= 0)
                dp[i][j] = (1LL * dp[i - 1][j - 1] * (j - 2 + ends)) % mod;
            dp[i][j] += (1LL * dp[i - 1][j + 1] * j) % mod;
            dp[i][j] %= mod;
        }
    }

    printf("%d\n", dp[N][1]);

    return 0;
}

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &st, &fn);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...