Cod sursa(job #168870)

Utilizator ErgoVicol Sergiu Constantin Ergo Data 31 martie 2008 20:38:04
Problema Sandokan Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.4 kb
// Sandokan
#include <fstream.h>

ifstream fin("sandokan.in");
ofstream fout("sandokan.out");

long A[2][5100];

int main(){
	int i,j,n,k,c;
      fin>>n>>k;
      c=n%(k-1);
      if (c==0) c=k-1;

      A[1][0]=1;
      A[0][0]=1;
      for (i=1;i<=n-1;i++){
         	for (j=1;j<=i;j++)
               	A[i%2][j]=(A[(i+1)%2][j]+A[(i+1)%2][j-1])%2000003;
      }
	fout<<A[(n-1)%2][c];
      fout.close();


}