제출 #231111

#제출 시각아이디문제언어결과실행 시간메모리
231111MKopchev캥거루 (CEOI16_kangaroo)C++14
100 / 100
62 ms16792 KiB
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e3+42,mod=1e9+7;

int dp[nmax][nmax];

int n,beg,en;

int rec(int to_place,int groups)
{
    if(to_place>n)return groups==1;

    if(dp[to_place][groups]!=-1)return dp[to_place][groups];

    long long ret=0;
    if(to_place==beg||to_place==en)
    {
        ret=rec(to_place+1,groups);//place with the first/last group
        ret+=rec(to_place+1,groups+1);//make new group
    }
    else
    {
        ret=1LL*(groups-1)*rec(to_place+1,groups-1);//merge 2 groups

        int positions=groups+1;

        if(to_place>beg)positions--;

        if(to_place>en)positions--;

        if(positions>0)ret+=1LL*positions*rec(to_place+1,groups+1);//create new group

    }


    ret=ret%mod;
    dp[to_place][groups]=ret;
    return ret;
}
int main()
{
    scanf("%i%i%i",&n,&beg,&en);

    memset(dp,-1,sizeof(dp));

    printf("%i\n",rec(1,0));
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

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