This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |