이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 1e3 + 5;
void add(int& a, int b){
a += b;
if(a >= mod) a -= mod;
}
int mul(int a, int b){
return 1LL * a * b % mod;
}
int n, L, a[MAX], dp[101][101][1001][3];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> L;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
if(n == 1){
cout << 1 << '\n';
return 0;
}
sort(a + 1, a + n + 1);
dp[1][1][0][0] = 1;
dp[1][1][0][1] = 2;
for(int i = 1; i < n; ++i){
for(int j = 1; j <= i; ++j){
for(int k = 0; k <= L; ++k){
for(int l = 0; l < 3; ++l){
int& ret = dp[i][j][k][l];
if(!ret) continue;
int sum = k + (2 * j - l) * (a[i + 1] - a[i]);
if((2 * j - l) < 0 || sum > L) continue;
add(dp[i + 1][j + 1][sum][l], mul(ret, j + 1 - l));
if(l < 2) add(dp[i + 1][j + 1][sum][l + 1], mul(ret, 2 - l));
add(dp[i + 1][j][sum][l], mul(ret, 2 * j - l));
if(l < 2) add(dp[i + 1][j][sum][l + 1], mul(ret, 2 - l));
if(j > 0) add(dp[i + 1][j - 1][sum][l], mul(ret, j - 1));
}
}
}
}
int res = 0;
for(int i = 0; i <= L; ++i){
add(res, dp[n][1][i][2]);
}
cout << res << '\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... |