ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1017. Staircases

help
Posted by hicham 1 Dec 2008 15:21
please sombody can help me I don't know what is th error the result of 212 is 995645335 so what is th fault? here my program:
import java.util.*;
import java.io.*;
import java.math.*;
public class stair {
    static int n;
    static Scanner in;
    static int t[][]=new int[501][501];
    //////////////////////////////////
    static int traiter(int p,int q)
    { if( p == 0 )
      return 1;
         if(q == 0)
             return 0;
         if(q > p)
             return t[p][p];
         return  t[p-q][q-1]+t[p][q-1];
    }

     public static void main(String[] arg)throws IOException
   {
       in=new Scanner(System.in);
       for(int i=0;i<501;i++)
           for(int j=0;j<501;j++)
               t[i][j]=traiter(i,j);
  n= in.nextInt();
   System.out.println((traiter(n,n)-1));
    in.close();}
}
Re: help
Posted by Anatoly 11 Sep 2009 00:57
I rewrote it to C++ and I've got AC :) But I was using __int64 instead of int. I think it's the heart of the matter, because 995645335 it's just the result of 212, but it's already near the top of int.

Edited by author 11.09.2009 00:59