题目链接:https://ac.nowcoder.com/acm/problem/16695
dp[i][j]表示把i划分为j部分的分法
状态转移方程:
划分部分大于原数,无法划分
划分全为1或划分为1部分
整数i-1划分出一个1或整数i-j划分出一个j
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
static const int MAX_N = 1005;
static const ll Mod = 1e9 + 7;
static const int N = 105;
static const ll INF = (ll)1 << 60;
int dp[205][7];
int main() {
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
if (j > i) dp[i][j] = 0;
else if (i == j || j == 1) dp[i][j] = 1;
else dp[i][j] = dp[i - 1][j - 1] + dp[i - j][j];
}
}
printf("%d\n", dp[n][k]);
return 0;
}