Files
python/TangDou/AcWing/JiShuDP/900_2.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

25 lines
698 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}