类型:DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028
思路:题目是求整数n的划分方案数。令状态
dp(p, n) = n的整数划分方案数其中规定最大的整数不大于p
有递推式:
dp(p, n) = (1) dp(n, n) n < p
(2) dp(p - 1, n) + dp(p, n - p) n >= p
枚举n的整数划分中最大整数是否是p
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define FOR(i,a,b) for(i = (a); i < (b); ++i)
#define FORE(i,a,b) for(i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(i = (a); i > (b); --i)
#define FORDE(i,a,b) for(i = (a); i >= (b); --i)
#define CLR(a,b) memset(a,b,sizeof(a))
#define PB(x) push_back(x)
const int MAXN = 122;
const int MAXM = 0;
const int hash_size = 25000002;
const int INF = 0x7f7f7f7f;
int dp[MAXN][MAXN];
int main() {
int i, j, n;
while(cin>>n) {
CLR(dp, 0);
dp[0][0] = 1;
FORE(i, 0, n)
dp[1][i] = 1;
FORE(i, 2, n)
FORE(j, 0, n)
if(j < i)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = dp[i][j - i] + dp[i - 1][j];
cout<<dp[n][n]<<endl;
}
return 0;
}