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

AC: Array simulate 2 digits big int, and Sum simulate 3 digits big int, otherwise(array simulate 3 digits big int) ==> TLE

Posted by hasan83 at 2011-12-04 15:07:57 on Problem 3181
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,k;
    __int64 sum=0,sum1=0,sum2=0,pp=pow(10.0,17),p[1001][101][2]={0};
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=n;j++)
            if(i==j||i==1)	
    	       p[j][i][0]=1;
            else
                if(j>i)
                    for(int b=1;b<=i;b++)
                    {
                        p[j][i][0]+=p[j-i][b][0];
                        p[j][i][1]+=p[j-i][b][1]+p[j][i][0]/pp;
                        p[j][i][0]%=pp;
    //                    p[j][i][2]+=p[j-i][b][2]+p[j][i][1]/pp;
      //                  p[j][i][1]%=pp;
                    }
        sum+=p[n][i][0];
        sum1+=p[n][i][1]+sum/pp;
        sum%=pp;
        sum2+=sum1/pp;
        sum1%=pp;
    }                    
    if(sum2!=0)cout<<sum2;
    if(sum1!=0)cout<<sum1;
    cout<<sum<<endl;
    return 0;
}

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