Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求助:怎么会超时啊?1000 100的结果都能很快出来

Posted by newstar04415 at 2008-02-28 15:28:27 on Problem 3181
import java.util.*;
import java.math.BigInteger;
public class Main
{
 public static void main(String args[])
{
  int n,k,b,i,j;
  BigInteger num[][]=new BigInteger[1001][101];
  BigInteger zero=new BigInteger("0");
  for(i=1;i<=1000;i++)
   for(j=1;j<=100;j++)
	   num[i][j]=zero;
  for(i=1;i<=1000;i++)
  {
   for(j=1;j<=100;j++)
   {
    if((i==j)||(j==1))	
    	num[i][j]=new BigInteger("1");
   
    else if(i>j)
    {
     for(b=1;b<=j;b++)
     num[i][j]=num[i][j].add(num[i-j][b]);
    }
   }
  }
  Scanner sc = new Scanner(System.in);
  n=sc.nextInt();
  k=sc.nextInt();
  BigInteger sum=new BigInteger("0");
  for(i=1;i<=k;i++)
     sum=sum.add(num[n][i]);
  System.out.println(sum);
  
}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator