您的位置:首页 > 其它

poj 1664 记忆化搜索

2014-02-17 09:15 274 查看
AC代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

int dp[11][11][11];

int record[100];

int DFS( int m, int n, int pre ){
if( m == 0 && n == 0 ){
//	for( int i = 3; i >= 1; i-- ){
//		cout << record[i] << " ";
//	}
//	cout << endl;
return 1;
}else if( n == 0 ){
return 0;
}
if( dp[m]
[pre] != -1 ){
return dp[m]
[pre];
}
int ans = 0;
for( int i = pre; i <= m; i++ ){
//	record
= i;
ans += DFS( m - i, n - 1, i );
}
return dp[m]
[pre] = ans;
}

int main(){
int T, N, M;

memset( dp, -1, sizeof( dp ) );

cin >> T;
while( T-- ){
cin >> M >> N;
cout << DFS( M, N, 0 ) << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: