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>
#define ST first
#define ND second
#define PB push_back
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 350 + 10, mod = 1e9 + 7;
int n;
int dp[nax][nax][2];
int bi[nax][nax];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
dp[0][0][0] = 1;
bi[0][0] = 1;
for(int i = 0; i <= n; ++i) {
for(int j = 0; j <= n; ++j) {
if(i == 0) {
bi[i][j] = (i == j);
} else if(j == 0) {
bi[i][j] = 1;
} else {
bi[i][j] = (bi[i - 1][j - 1] + bi[i - 1][j]) % mod;
}
//cout << i << " " << j << ": " << bi[i][j] << "\n";
}
}
for(int i = 1; i <= n; ++i) {
for(int g = 0; g <= n; ++g) {
for(int j = 0; j <= g; ++j) {
if(i != j) dp[i][g][0] = (dp[i][g][0] + (ll)bi[g][j] * dp[i - 1][g - j][0]) % mod;
dp[i][g][1] = (dp[i][g][1] + (ll)bi[g][j] * dp[i - 1][g - j][1]) % mod;
}
if(g >= i) {
dp[i][g][1] = (dp[i][g][1] + (ll)bi[g][i] * dp[i - 1][g - i][0]) % mod;
}
}
}
cout << dp[n][n][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |