#include "bits/stdc++.h"
#define pb(x) push_back(x)
#define fil(x, y) memset(x, y, sizeof(x))
#define ll long long
#define ff first
#define ss second
#define printp(x) x.ff << " " << x.ss
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mp(x, y) make_pair(x,y)
#define inf 1073741823
#define infll 4611686018427387903
#define M 1000000007
#define db(x) cout << x << " ";
#define N 357
#define sz size
#define sm 0.0000007
#define ins insert
#define ers erase
#define all(k) k.begin(), k.end()
#define cnt count
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
using namespace std;
ll mem[N][N][2];
ll ncr[N][N];
int n;
ll dp(int pos, int x, bool g)
{
if(pos > n)
{
if(x == 0 && g == 1)
return 1;
return 0;
}
if(mem[pos][x][g] != -1)
return mem[pos][x][g];
ll ans = 0;
for(int i = 0;i <= x;i++)
{
bool k = g;
if(i == pos)
k = 1;
ans = (ans + (dp(pos + 1, x - i, k)*ncr[x][i]) % M) % M;
}
return mem[pos][x][g] = ans;
}
int main()
{
fastio;
cin >> n;
fil(mem, -1);
for(int i = 0;i <= 350;i++)
{
for(int j = 0;j <= i;j++)
{
if(j == 0 || j == i)
ncr[i][j] = 1;
else
{
ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % M;
}
}
}
ll ans = dp(1, n, 0);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3276 KB |
Output is correct |
2 |
Correct |
2 ms |
3276 KB |
Output is correct |
3 |
Correct |
2 ms |
3276 KB |
Output is correct |
4 |
Correct |
3 ms |
3276 KB |
Output is correct |
5 |
Correct |
2 ms |
3276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3276 KB |
Output is correct |
2 |
Correct |
2 ms |
3276 KB |
Output is correct |
3 |
Correct |
2 ms |
3276 KB |
Output is correct |
4 |
Correct |
3 ms |
3276 KB |
Output is correct |
5 |
Correct |
2 ms |
3276 KB |
Output is correct |
6 |
Correct |
2 ms |
3276 KB |
Output is correct |
7 |
Correct |
2 ms |
3224 KB |
Output is correct |
8 |
Correct |
2 ms |
3276 KB |
Output is correct |
9 |
Correct |
3 ms |
3276 KB |
Output is correct |
10 |
Correct |
2 ms |
3276 KB |
Output is correct |
11 |
Correct |
2 ms |
3264 KB |
Output is correct |
12 |
Correct |
2 ms |
3268 KB |
Output is correct |
13 |
Correct |
2 ms |
3208 KB |
Output is correct |
14 |
Correct |
2 ms |
3276 KB |
Output is correct |
15 |
Correct |
2 ms |
3276 KB |
Output is correct |
16 |
Correct |
3 ms |
3276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3276 KB |
Output is correct |
2 |
Correct |
2 ms |
3276 KB |
Output is correct |
3 |
Correct |
2 ms |
3276 KB |
Output is correct |
4 |
Correct |
3 ms |
3276 KB |
Output is correct |
5 |
Correct |
2 ms |
3276 KB |
Output is correct |
6 |
Correct |
2 ms |
3276 KB |
Output is correct |
7 |
Correct |
2 ms |
3224 KB |
Output is correct |
8 |
Correct |
2 ms |
3276 KB |
Output is correct |
9 |
Correct |
3 ms |
3276 KB |
Output is correct |
10 |
Correct |
2 ms |
3276 KB |
Output is correct |
11 |
Correct |
2 ms |
3264 KB |
Output is correct |
12 |
Correct |
2 ms |
3268 KB |
Output is correct |
13 |
Correct |
2 ms |
3208 KB |
Output is correct |
14 |
Correct |
2 ms |
3276 KB |
Output is correct |
15 |
Correct |
2 ms |
3276 KB |
Output is correct |
16 |
Correct |
3 ms |
3276 KB |
Output is correct |
17 |
Correct |
223 ms |
3276 KB |
Output is correct |
18 |
Correct |
4 ms |
3276 KB |
Output is correct |
19 |
Correct |
48 ms |
3276 KB |
Output is correct |
20 |
Correct |
2 ms |
3256 KB |
Output is correct |
21 |
Correct |
301 ms |
3300 KB |
Output is correct |
22 |
Correct |
35 ms |
3276 KB |
Output is correct |
23 |
Correct |
5 ms |
3276 KB |
Output is correct |
24 |
Correct |
64 ms |
3276 KB |
Output is correct |
25 |
Correct |
45 ms |
3276 KB |
Output is correct |
26 |
Correct |
88 ms |
3292 KB |
Output is correct |
27 |
Correct |
435 ms |
3308 KB |
Output is correct |
28 |
Correct |
443 ms |
3276 KB |
Output is correct |
29 |
Correct |
440 ms |
3304 KB |
Output is correct |
30 |
Correct |
451 ms |
3312 KB |
Output is correct |
31 |
Correct |
429 ms |
3276 KB |
Output is correct |
32 |
Correct |
466 ms |
3312 KB |
Output is correct |
33 |
Correct |
453 ms |
3308 KB |
Output is correct |
34 |
Correct |
448 ms |
3324 KB |
Output is correct |
35 |
Correct |
457 ms |
3396 KB |
Output is correct |
36 |
Correct |
503 ms |
3304 KB |
Output is correct |
37 |
Correct |
465 ms |
3396 KB |
Output is correct |