#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=50+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[N];
ll dp1[N][10*1000+10][2][2],dp2[N][10*1000+10][2][2],sp1[N][10*1000+10][2][2],sp2[N][10*1000+10][2][2];
void solve(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;t[i]--,i++) cin>>t[i];
if(1==n){
cout<<k<<"\n";
return;
}
sort(t+1,t+1+n);
dp1[0][0][1][1]=1;
for(int i=1;i<=n;i++){
for(int i2=0;i2<=n;i2++){
for(int k1=0;k1<2;k1++) for(int k2=0;k2<2;k2++){
sp1[i2][0][k1][k2]=dp1[i2][0][k1][k2];
for(int sum=1;sum<=k;sum++)
(sp1[i2][sum][k1][k2]=sp1[i2][sum-1][k1][k2]+dp1[i2][sum][k1][k2])%=mod;
}
}
for(int i2=0;i2<=n;i2++){
for(int k1=0;k1<2;k1++) for(int k2=0;k2<2;k2++){
ll curr=dp1[i2][0][k1][k2];
sp2[i2][0][k1][k2]=dp1[i2][0][k1][k2];
for(int sum=1;sum<=k;sum++)
(curr+=dp1[i2][sum][k1][k2])%=mod,(sp2[i2][sum][k1][k2]=sp2[i2][sum-1][k1][k2]+curr)%=mod;
}
}
//nowa spojna
for(int i2=1;i2<=n;i2++){
for(int sum=1;sum<=k;sum++){
(dp2[i2][sum][0][0]=dp1[i2-1][sum-1][0][0]*(ll)(i2-2)+sp1[i2-1][sum-1][1][0]+sp1[i2-1][sum-1][0][1])%=mod;
(dp2[i2][sum][1][0]=dp1[i2-1][sum-1][1][0]*(ll)(i2-1)+sp1[i2-1][sum-1][1][1])%=mod;
(dp2[i2][sum][1][1]=dp1[i2-1][sum-1][1][1]*(ll)(i2))%=mod;
(dp2[i2][sum][0][1]=dp1[i2-1][sum-1][0][1]*(ll)(i2-1)+sp1[i2-1][sum-1][1][1])%=mod;
}
}
//na koniec spojnej
for(int i2=1;i2<=n;i2++){
for(int sum=t[i]+1;sum<=k;sum++){
for(int k1=0;k1<2;k1++) for(int k2=0;k2<2;k2++){
(dp2[i2][sum][k1][k2]+=sp1[i2][sum-t[i]-1][k1][k2]*(ll)(i2*2-(k1^1)-(k2^1)))%=mod;
if(!k1) (dp2[i2][sum][k1][k2]+=sp2[i2][sum-t[i]-1][1][k2])%=mod;
if(!k2) (dp2[i2][sum][k1][k2]+=sp2[i2][sum-t[i]-1][k1][1])%=mod;
}
}
}
//laczenie spojnych
for(int i2=1;i2<n;i2++){
for(int sum=(t[i]<<1)+1;sum<=k;sum++){
for(int k1=0;k1<2;k1++) for(int k2=0;k2<2;k2++){
(dp2[i2][sum][k1][k2]+=sp2[i2+1][sum-(t[i]<<1)-1][k1][k2]*(ll)(i2))%=mod;
}
}
}
swap(dp1,dp2);
memset(dp2,0,sizeof(dp2));
}
cout<<dp1[1][k][0][0]<<"\n";
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
int tt=1;
while(tt--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
69884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
44816 KB |
Output is correct |
2 |
Correct |
43 ms |
39296 KB |
Output is correct |
3 |
Correct |
139 ms |
44824 KB |
Output is correct |
4 |
Correct |
51 ms |
40360 KB |
Output is correct |
5 |
Correct |
139 ms |
44824 KB |
Output is correct |
6 |
Correct |
66 ms |
39996 KB |
Output is correct |
7 |
Correct |
151 ms |
44748 KB |
Output is correct |
8 |
Correct |
77 ms |
38660 KB |
Output is correct |
9 |
Correct |
55 ms |
39940 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
38732 KB |
Output is correct |
2 |
Correct |
130 ms |
38404 KB |
Output is correct |
3 |
Correct |
193 ms |
38764 KB |
Output is correct |
4 |
Correct |
148 ms |
38532 KB |
Output is correct |
5 |
Correct |
197 ms |
38764 KB |
Output is correct |
6 |
Correct |
119 ms |
38148 KB |
Output is correct |
7 |
Correct |
225 ms |
38772 KB |
Output is correct |
8 |
Correct |
84 ms |
38184 KB |
Output is correct |
9 |
Correct |
132 ms |
38476 KB |
Output is correct |
10 |
Correct |
77 ms |
38092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
69884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |