#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pii >
#define Graph vector<vector<int> >
#define WGraph vector<vector<pii>>
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define mp(a,b) make_pair(a,b)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bound(i,j,n,m) ((i)<n&&(j)<m&&(i)>=0&&(j)>=0)
#define all(container) container.begin(),container.end()
#define fi first
#define se second
#define pub push_back
#define sqr(x) ((x)*(x))
#define LL_MAX 0x7fffffffffffffff
#define getPos(i,j,m) ((i)*m+(j))
const ll mod=1000000007;
const int offset=200001;
int dp[2][102][offset+2005*2][3];
int a[101];
void solvecases(int cse)
{
int n,l;
cin>>n>>l;
for(int i=0;i<n;++i)
cin>>a[i];
sort(a,a+n);
for(int i=1;i<n;++i)
a[i]=a[i]-a[0];
a[0]=0;
// for(int i=0;i<n;++i)
// cout<<a[i]<<' ';
// cout<<'\n';
dp[0][1][0+offset][0]=1;
dp[0][1][0+offset][1]=2;
dp[0][1][0+offset][2]=1;
int cur=1;
int sum=0;
for(int i=1;i<n;++i)
{
for(int j=1;j<=i+1;++j){
for(int cost=-2*sum-2*a[i];cost<=2005;++cost){
for(int k=0;k<3;++k){
dp[cur][j][cost+offset][k]=0;
}
}
}
int prv=cur^1;
for(int j=1;j<=i;++j)
{
for(int cost=-2*sum;cost<=2005;++cost)
{
if(dp[prv][j][cost+offset][0])
{
dp[cur][j+1][cost+offset-2*a[i]][0]
=(dp[cur][j+1][cost+offset-2*a[i]][0]+
(ll)dp[prv][j][cost+offset][0]*(j+1))%mod;
dp[cur][j+1][cost+offset-a[i]][1]
=(dp[cur][j+1][cost+offset-a[i]][1]+
(ll)dp[prv][j][cost+offset][0]*(2))%mod;
if(j>1&&cost+2*a[i]<=2005)
{
dp[cur][j-1][cost+offset+2*a[i]][0]
=(dp[cur][j-1][cost+offset+2*a[i]][0]+
(ll)dp[prv][j][cost+offset][0]*(j-1))%mod;
}
dp[cur][j][cost+offset][0]=
(dp[cur][j][cost+offset][0]+
(ll)dp[prv][j][cost+offset][0]*(2*j))%mod;
if(cost+a[i]<=2005){
dp[cur][j][cost+offset+a[i]][1]=
(dp[cur][j][cost+offset+a[i]][1]+
(ll)dp[prv][j][cost+offset][0]*2)%mod;
}
}
if(dp[prv][j][cost+offset][1])
{
dp[cur][j+1][cost+offset-2*a[i]][1]
=(dp[cur][j+1][cost+offset-2*a[i]][1]+
(ll)dp[prv][j][cost+offset][1]*(j))%mod;
dp[cur][j+1][cost+offset-a[i]][2]
=(dp[cur][j+1][cost+offset-a[i]][2]+
(ll)dp[prv][j][cost+offset][1])%mod;
if(j>1&&cost+2*a[i]<=2005)
{
dp[cur][j-1][cost+offset+2*a[i]][1]
=(dp[cur][j-1][cost+offset+2*a[i]][1]+
(ll)dp[prv][j][cost+offset][1]*(j-1))%mod;
}
dp[cur][j][cost+offset][1]=
(dp[cur][j][cost+offset][1]+
(ll)dp[prv][j][cost+offset][1]*(2*j-1))%mod;
if(cost+a[i]<=2005){
dp[cur][j][cost+offset+a[i]][2]=
(dp[cur][j][cost+offset+a[i]][2]+
(ll)dp[prv][j][cost+offset][1])%mod;
}
}
if(dp[prv][j][cost+offset][2])
{
if(j>1){
dp[cur][j+1][cost+offset-2*a[i]][2]
=(dp[cur][j+1][cost+offset-2*a[i]][2]+
(ll)dp[prv][j][cost+offset][2]*(j-1))%mod;
if(cost+2*a[i]<=2005){
dp[cur][j-1][cost+offset+2*a[i]][2]=
(dp[cur][j-1][cost+offset+2*a[i]][2]+
(ll)dp[prv][j][cost+offset][2]*(j-1)
)%mod;
}
dp[cur][j][cost+offset][2]=
(dp[cur][j][cost+offset][2]+
(ll)dp[prv][j][cost+offset][2]*2*(j-1))%mod;
}
}
}
}
cur^=1;
sum+=a[i];
}
cur^=1;
ll ans=0;
for(int i=0;i<=l;++i)
ans+=dp[cur][1][i+offset][2];
// for(int i=-offset;i<0;++i)
// assert(!dp[cur][1][i+offset][2]);
ans%=mod;
cout<<ans<<'\n';
}
int main()
{
fastio;
//build(100000);
//brute();
int t=1;
//cout<<fixed<<setprecision(2);
//cin>>t;
for(int i=1;i<=t;i++)
{
solvecases(i);
//brute(i);
}
}
/*
4 10
3 6 2 9
8 35
3 7 1 5 10 2 11 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
2128 KB |
Output is correct |
6 |
Correct |
2 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
980 KB |
Output is correct |
2 |
Correct |
2 ms |
1364 KB |
Output is correct |
3 |
Correct |
2 ms |
1236 KB |
Output is correct |
4 |
Correct |
2 ms |
1492 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
2 ms |
1364 KB |
Output is correct |
7 |
Correct |
2 ms |
1224 KB |
Output is correct |
8 |
Correct |
2 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
2 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
456 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
2128 KB |
Output is correct |
6 |
Correct |
2 ms |
1492 KB |
Output is correct |
7 |
Correct |
2 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
840 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
1364 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
2 ms |
1492 KB |
Output is correct |
15 |
Correct |
2 ms |
1492 KB |
Output is correct |
16 |
Correct |
2 ms |
1364 KB |
Output is correct |
17 |
Correct |
2 ms |
1224 KB |
Output is correct |
18 |
Correct |
2 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
1236 KB |
Output is correct |
20 |
Correct |
2 ms |
1364 KB |
Output is correct |
21 |
Correct |
17 ms |
4200 KB |
Output is correct |
22 |
Correct |
199 ms |
18144 KB |
Output is correct |
23 |
Execution timed out |
2072 ms |
156300 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |