这个题与poj1664一样的类型的题目,但是这题的数据量比较大,如果像1664那样做,就会超时,因为有很多重复的计算;
View Code
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #include<cstring> #include<vector> #include<string> #define LL long long using namespace std; LL dp[224][224]; void Init( ) { for( int i = 0 ; i <= 200; i ++ ) { dp[1][i] = 1;dp[i][0] = 1; dp[i][1] = 1; } for( int i = 2 ;i <= 200 ; i++ ) { for( int j = 1; j <=200 ; j ++ ) { if( j >= i ) dp[i][j] = dp[i-1][j] + dp[i][j-i]; else dp[i][j] = dp[j][j]; } } } int main( ) { int n, m; Init(); while( scanf( "%d %d",&m,&n ),n|m ) { printf( "%I64d\n",dp[n][m-n] ); } //system( "pause" ); return 0; }