- 整数划分
两种方案:
第一种:f[i][j] = f[i-1][j-1]+f[i-j][j]//i表示数量,j表示分几个数
#include <iostream>
using namespace std;
const int N = 1050;
const int mod = 1e9 + 7;
int f[N][N];
int main()
{int n;cin >> n;f[0][0] = 1;for (int i = 1; i <= n; i++){for (int j = 1; j <= i; j++){f[i][j] = (f[i - 1][j - 1] + f[i - j][j]) % mod;}}int res = 0;for (int i = 1; i <= n; i++){res = (res + f[n][i]) % mod;}cout << res << endl;
}
第二种:f[i][j] = f[i-1][j]+f[i][j-1];//i表示1-i中选,总体积正好为j的选法(转化成背包问题)
#include <iostream>
using namespace std;
const int N = 1050;
const int mod = 1e9 + 7;
int f[N];
int main()
{int n;cin >> n;f[0] = 1;for (int i = 1; i <= n; i++){for (int j = i; j <= n; j++){f[j] = (f[j] + f[j - i]) % mod;}}cout << f[n] << endl;return 0;
}