#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int mod = 1e6 + 7;
void nxt(vector<int> &v) {
int n = (int) v.size();
vector<int> prefmax(n);
prefmax[0] = 1;
for(int i = 1; i < n; i++) {
prefmax[i] = max(prefmax[i - 1], v[i]);
}
if(prefmax[n - 1] == n) {
// 1 2 3 ... n
return;
}
for(int i = n - 1; i >= 0; i--) {
if(prefmax[i - 1] >= v[i]) {
v[i]++;
return;
}
v[i] = 1;
}
}
void solve() {
int n;
cin >> n;
vector<int> dp(1 + n, 0);
dp[1] = 1;
for(int i = 2; i <= n; i++) {
for(int j = i; j >= 1; j--) {
dp[j] = dp[j] * j + dp[j - 1];
dp[j] %= mod;
}
}
int res = 0;
for(int i = 1; i <= n; i++) {
res += dp[i];
res %= mod;
}
cout << res << "\n";
/*for(int n = 1; n <= 14; n++) {
vector<int> a(n, 1);
vector<int> b(n);
for(int i = 0; i < n; i++) {
b[i] = i + 1;
}
int cnt = 1;
while(a != b) {
nxt(a);
cnt++;
}
cout << n << ": " << cnt << "\n";
}*/
/*int n;
cin >> n;
vector<int> v(n, 1);
vector<int> goal(n);
for(int i = 0; i < n; i++) {
cin >> goal[i];
}
int ans = 0;
ans++;
while(v != goal) {
nxt(v);
ans++;
}
ans %= mod;
cout << ans << "\n";*/
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
76 ms |
488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |