Cod sursa(job #1754887)

Utilizator giotoPopescu Ioan gioto Data 8 septembrie 2016 21:56:13
Problema Sandokan Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <cstdio>
#include <algorithm>
#define MOD 2000003
using namespace std;

int n,k,c[2][5000];
int main()
{
    freopen("sandokan.in", "r", stdin);
    freopen("sandokan.out", "w", stdout);
    scanf("%d%d", &n, &k);
    int m=n;
    while(m>=k) m=m-k+1;
    if(m<=1) {printf("1");return 0;}
    --n;--m;int l=0;
    c[l][1]=1;
    for(int i=2;i<=n;++i,l=1-l){
        c[1-l][1]=i;
        for(int j=2;j<=i&&j<=m;++j)
            c[1-l][j]=(c[l][j]+c[l][j-1])%MOD;
    }
    printf("%d", c[l][m]);
    return 0;
}