#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define fi first
#define se second
#define pb push_back
#define pob pop_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<char,int> PCI;
typedef pair<int,char> PIC;
typedef vector<int> VI;
typedef vector<int,int> VII;
typedef unordered_map<int,int> UII;
typedef set<int> SI;
typedef vector<string> VS;
typedef vector<PII> VPII;
const int INF = 0x3f3f3f3f,MOD = 1e9 + 7;
const int N = 1010,M = N * 2;
const double PI = 3.1415926;
int n,m;
int f[N][N];
void solve(){
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;
}
}
LL res = 0;
for(int i = 1;i <= n;i++)res = (res + f[n][i]) % MOD;
cout << res << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T = 1;//cin >> T;
while(T--)solve();
return 0;
}
完全背包做法
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define for1(i, n) for (int i = 1; i <= int(n); i++)
#define fi first
#define se second
#define pb push_back
#define pob pop_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<string,int> PSI;
typedef pair<int,string> PIS;
typedef pair<char,int> PCI;
typedef pair<int,char> PIC;
typedef vector<int> VI;
typedef vector<int,int> VII;
typedef unordered_map<int,int> UII;
typedef set<int> SI;
typedef vector<string> VS;
typedef vector<PII> VPII;
const int INF = 0x3f3f3f3f,MOD = 1e9 + 7;
const int N = 1010,M = N * 2;
const double PI = 3.1415926;
int n,m;
int f[N];
void solve(){
cin >> n;
f[0] = 1;
//完全背包做法
//物品为n个
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;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int T = 1;//cin >> T;
while(T--)solve();
return 0;
}