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>
#pragma GCC optimize("O3")
#define ll long long
#define oo 1e9 + 9
#define pii pair<int, int>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e4 + 100;
int comb[MAX][MAX];
void preCalc(){
comb[0][0] = 1;
for (int i = 1; i < MAX; i++)
{
comb[i][0] = comb[i][i] = 1;
for (int j = 1; j < i; j++)
{
comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
comb[i][j] %= MOD;
}
}
}
int main(){
preCalc();
int n, l; cin >> n >> l;
int arr[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int idx[n];
for (int i = 0; i < n; i++)
{
idx[i] = i;
}
int ans = 0;
do{
int d = 1;
for (int i = 0; i < n - 1; i++)
{
d += max(arr[idx[i]], arr[idx[i + 1]]);
}
if(d > l) continue;
ans += comb[l - d + n][n];
ans %= MOD;
}
while(next_permutation(idx, idx + n));
cout << ans << '\n';
}
# | 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... |