#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=105,mod=1e9+7,L=6005;
int t,n,l,a[N],dp[2][N][L][2][2],cnt,fix[N];
vector<int>v;
void go(int cur){
if(cur==n+1) {
int ans = 0;
for(int i=1;i<v.size();i++) {
ans+=abs(a[v[i]] - a[v[i-1]]);
}
if(ans <= l) cnt++;
}
for(int i=1;i<=n;i++){
if(!fix[i]) {
fix[i] = 1;
v.push_back(i);
go(cur+1);
v.pop_back();
fix[i] = 0;
}
}
}
main(){
cin>>n>>l;
for(int i=1;i<=n;i++) {
cin >> a[i];
}
sort(a+1,a+n+1);
dp[0][1][(a[2] - a[1]) * 2][0][0] = 1;
dp[0][1][a[2] - a[1] ][0][1] = dp[0][1][a[2] - a[1]][1][0] = 1;
a[n+1] = a[n];
for(int i=2;i<=n;i++){
for(int j=1;j<=i;j++)
for(int sum = 0;sum <= 3*l;sum++)
for(int f1 = 0; f1<2; f1++)
for(int f2=0; f2<2; f2++) dp[1][j][sum][f1][f2] = 0;
for(int j=1;j<=i;j++) {
for(int sum = 0;sum <= 3*l;sum++)
for(int f1 = 0; f1<2; f1++){
for(int f2=0; f2<2; f2++) {
dp[1][j][sum + (j*2 - f1 - f2) * (a[i+1] - a[i]) ][f1][f2] = dp[0][j][sum][f1][f2];
dp[0][j][sum][f1][f2] = 0;
}
}
}
int diff = a[i+1] - a[i];
for(int j=1; j<=i; j++) {
for(int sum=0; sum<=3*l;sum++){
for(int f1=0; f1<2;f1++){
for(int f2=0;f2<2;f2++) {
if(f1) {
// dasackisshi
if(!f2) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2]*j%mod ;
else {
if(i == n) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2];
else dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][0][f2] * (j-1)%mod;
}
if(sum - diff >= 0)dp[0][j][sum][f1][f2] += dp[1][j-1][sum - diff][0][f2];
}
if(f2) {
if(!f1) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0]*j%mod ;
else {
if(i == n) dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0];
else dp[0][j][sum][f1][f2] += dp[1][j][sum + diff][f1][0] * (j-1)%mod;
}
if(sum - diff >= 0)dp[0][j][sum][f1][f2] += dp[1][j-1][sum - diff][f1][0];
}
////////////
dp[0][j][sum][f1][f2] += dp[1][j][sum][f1][f2] * (2*j - f1 - f2)%mod;
///////////
dp[0][j][sum][f1][f2] += dp[1][j-1][sum - 2*diff][f1][f2];
//////////
if(!f1 && !f2) dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * (j + 1)%mod)%mod;
else if(f1 && f2 ){
if(j==1 && i!=n) {}
else
if(j==1) {
dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2]%mod;
}
else {
dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * (j - 1)%mod)%mod;
}
}
else dp[0][j][sum][f1][f2] += dp[1][j+1][sum + 2*diff][f1][f2] * (j * j%mod)%mod;
dp[0][j][sum][f1][f2]%=mod;
}
}
}
}
}
int ans = 0;
for(int sum=0;sum<=l;sum++)
ans += dp[0][1][sum][1][1],ans%=mod;
cout<<ans<<endl;
}
Compilation message
skyscraper.cpp: In function 'void go(long long int)':
skyscraper.cpp:12:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=1;i<v.size();i++) {
| ~^~~~~~~~~
skyscraper.cpp: At global scope:
skyscraper.cpp:27:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
4 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |