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;
const int Nmax = 103, Kmax = 1003;
const int Mod = 1e9 + 7;
typedef long long ll;
int N, K, i, j, k, F, S, new_k, a[Nmax];
int now[Nmax][Kmax][2][2], old[Nmax][Kmax][2][2];
void add_to(int &x, int y, int z)
{
x = (x + (ll)y*z) % Mod;
}
int main()
{
// freopen("input", "r", stdin);
cin >> N >> K;
for(i=1; i<=N; ++i) cin >> a[i];
sort(a+1, a+N+1);
for(i=1; i<N; ++i) a[i] = a[i+1] - a[i];
now[0][0][1][1] = now[0][0][0][1] = now[0][0][1][0] = now[0][0][0][0] = 1;
for(i=1; i<N; ++i)
{
memcpy(old, now, sizeof(now));
memset(now, 0, sizeof(now));
for(j=0; j<=N; ++j)
for(k=0; k<=K; ++k)
for(F=0; F<2; ++F)
for(S=0; S<2; ++S)
{
new_k = k + a[i] * (2 * j + F + S);
if(new_k > K) continue;
add_to(now[j+1][new_k][F][S], j, old[j][k][F][S]);
add_to(now[j][new_k][F][S], 2*j, old[j][k][F][S]);
if(j) add_to(now[j-1][new_k][F][S], j, old[j][k][F][S]);
if(F)
{
add_to(now[j+1][new_k][1][S], 1, old[j][k][F][S]);
add_to(now[j][new_k][1][S], 1, old[j][k][F][S]);
add_to(now[j+1][new_k][0][S], 1, old[j][k][F][S]);
add_to(now[j][new_k][0][S], 1, old[j][k][F][S]);
}
if(S)
{
add_to(now[j+1][new_k][F][1], 1, old[j][k][F][S]);
add_to(now[j][new_k][F][1], 1, old[j][k][F][S]);
add_to(now[j+1][new_k][F][0], 1, old[j][k][F][S]);
add_to(now[j][new_k][F][0], 1, old[j][k][F][S]);
}
}
}
int ans = 0;
for(i=0; i<=K; ++i) add_to(ans, 1, now[0][i][0][0]);
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |