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

Re:滚存+0(m*n)的时间复杂度也TLE疯了,谁教教怎么个优化法!!!!!!

Posted by busycai at 2006-09-30 17:03:54 on Problem 3014
In Reply To:滚存+0(m*n)的时间复杂度也TLE疯了,谁教教怎么个优化法!!!!!! Posted by:busycai at 2006-09-30 17:03:12
> #include <stdio.h>
> #include <string.h>
> 
> int f[2][4510];
> 
> int main () {
>     int n , m , a , b , i , j , k , rs ;
>     while ( scanf ( "%d%d" , &n , &m ) != EOF ) {
>         a = 1 ; 
>         b = 0 ;
>         memset ( f , 0 , sizeof ( f ) ) ;
>         for ( i = 0 ; i <= m ; i ++ ) f [1][i] = 1 ;
>         for ( k = 2 ; k <= n ; k ++ ) {
>             for( i = 0 ; i <= m ; i ++) {
>                 f[b][i] += f[a][i] ;
>                 f[b][i] %= 1000000007 ;
>                 if ( i >= k ) {
>                 f[b][i] += f[b][i-k] ;
>                 f[b][i] %= 1000000007 ;
>                 }                
>             }
>             memset ( f[a] , 0 , sizeof ( f[a] ) ) ;
>             a = 1-a ;
>             b = 1-b ;
>         }
>         printf ("%d\n" , f[a][m] ) ;
>     }
>     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