Cod sursa(job #164056)

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