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 finish(x) return cout << x << endl, 0
#define ll long long
const int N = 351;
int n, dp[N][N][2], C[N][N], mod = 1e9 + 7;
int solve(int idx, int s, bool b){
if(idx == n + 1) return s == 0 && b;
int &ret = dp[idx][s][b];
if(ret != -1) return ret;
ret = 0;
for(int i = 0 ; i <= s ; i++){
ret = (ret + 1LL * C[s][i] * solve(idx + 1, s - i, b | (i == idx))) % mod;
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, sizeof dp);
C[0][0] = 1;
for(int i = 1 ; i < N ; i++){
C[i][0] = 1;
for(int j = 1 ; j < N ; j++){
C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
if(C[i][j] >= mod) C[i][j] -= mod;
}
}
cin >> n;
cout << solve(1, n, 0) << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |