Cod sursa(job #179230)

Utilizator razvi9Jurca Razvan razvi9 Data 15 aprilie 2008 19:17:43
Problema Sandokan Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<cstdio>
#include<string>
int last[5001],next[5001],i,j,n,k;
const int mod=2000003;
int main()
{
	freopen("sandokan.in","r",stdin);
	freopen("sandokan.out","w",stdout);
	scanf("%d %d",&n,&k);
	if(n%(k-1)) k=n%(k-1);
	else k--;
	next[0]=1;
	for(i=1;i<n;i++)
	{
		memcpy(last,next,sizeof(next));
		next[0]=1;
		for(j=1;j<k && j<i;j++)
		{
			next[j]=last[j]+last[j-1];
			if(next[j]>mod) next[j]-=mod;
		}
	}
	printf("%d\n",next[k-1]);
	fclose(stdout);	
}