/*
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|../\..|
|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|\/..\/|
|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|/....\|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|\..../|
|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|/\../\|
|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|..\/..|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
*/
#include <bits/stdc++.h>
#define fore(i, a, b) for (signed i = (a), i##_last = (b); i < i##_last; ++i)
#define fort(i, a, b) for (signed i = (a), i##_last = (b); i <= i##_last; ++i)
#define ford(i, a, b) for (signed i = (a), i##_last = (b); i >= i##_last; --i)
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double;
template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;};
template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;};
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
int findPeriod(ll a, int m) {
int x = 1;
map<int, int> f;
for (int i = 0;; ++i) {
const auto g = f.find(x);
if (g != f.end())
return i - (g -> se);
f[x] = i;
x = (x * a) % m;
}
}
const int maxN = 355, MOD = 1e9 + 7;
int n;
int C(int n, int k) {
static int c[maxN][maxN];
static bool seen[maxN][maxN];
if (n == k)
return 1;
if (n < k || n <= 0)
return 0;
if (!seen[n][k]) {
seen[n][k] = true;
c[n][k] = (C(n - 1, k) + C(n - 1, k - 1)) % MOD;
}
return c[n][k];
}
int DP(int x, int y, bool z) {
static int dp[maxN][maxN][2];
static bool seen[maxN][maxN][2];
if (x <= 0)
return !y && z;
if (!seen[x][y][z]) {
seen[x][y][z] = true;
fort(t, 0, y)
if (t == x) {
if (z)
continue;
(dp[x][y][z] += 1LL * ((DP(x - 1, y - t, false) + DP(x - 1, y - t, true)) % MOD) * C(y, t) % MOD) %= MOD;
} else
(dp[x][y][z] += 1LL * DP(x - 1, y - t, z) * C(y, t) % MOD) %= MOD;
}
return dp[x][y][z];
}
int main() {
int n;
#ifdef LOCAL
freopen("input.INP", "r", stdin);
#endif // LOCAL
cin.tie(0) -> sync_with_stdio(0);
cout.tie(0);
cin >> n;
cout << DP(n, n, false) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
146 ms |
1792 KB |
Output is correct |
18 |
Correct |
1 ms |
592 KB |
Output is correct |
19 |
Correct |
37 ms |
1124 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
193 ms |
1936 KB |
Output is correct |
22 |
Correct |
22 ms |
1108 KB |
Output is correct |
23 |
Correct |
2 ms |
672 KB |
Output is correct |
24 |
Correct |
45 ms |
1240 KB |
Output is correct |
25 |
Correct |
29 ms |
1104 KB |
Output is correct |
26 |
Correct |
58 ms |
1388 KB |
Output is correct |
27 |
Correct |
274 ms |
2176 KB |
Output is correct |
28 |
Correct |
275 ms |
2088 KB |
Output is correct |
29 |
Correct |
273 ms |
2156 KB |
Output is correct |
30 |
Correct |
281 ms |
2204 KB |
Output is correct |
31 |
Correct |
284 ms |
2148 KB |
Output is correct |
32 |
Correct |
284 ms |
2188 KB |
Output is correct |
33 |
Correct |
278 ms |
2208 KB |
Output is correct |
34 |
Correct |
284 ms |
2128 KB |
Output is correct |
35 |
Correct |
290 ms |
2176 KB |
Output is correct |
36 |
Correct |
296 ms |
2124 KB |
Output is correct |
37 |
Correct |
294 ms |
2196 KB |
Output is correct |