Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
滚存+0(m*n)的时间复杂度也TLE疯了,谁教教怎么个优化法!!!!!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator