This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int MOD = 1e9 + 7;
int n;
int f[N][N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) f[i][0] = 1;
for (int i = 1; i <= n; i++) // 枚举每个物品,物品的序号与物品的体积是相等的,都是i
for (int j = 1; j <= n; j++) { // 枚举背包容量j
if (j >= i) // ① 背包容量j>=当前体积i,可以选择当前数字
f[i][j] = (f[i][j - i] + f[i - 1][j]) % MOD;
else
f[i][j] = f[i - 1][j] % MOD; // ② 放弃当前数字
}
cout << f[n][n] << endl;
return 0;