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>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e2+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
void add(ll &A,ll B){
A=(A+B)%MOD;
return;
}
ll n,k,u[N],dp[N][N][1005][3],ans;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k;
REP1(i,n)cin>>u[i];
sort(u+1,u+n+1);
dp[1][1][0][0]=dp[1][1][0][2]=1;
dp[1][1][0][1]=2;
REP1(i,n-1){
REP1(j,i){
REP(cost,k+1){
REP(ty,3){
ll price=cost+(u[i+1]-u[i])*(2*j-ty);
if(price>k)continue;
add(dp[i+1][j][price][ty],dp[i][j][cost][ty]*(2*j-ty)%MOD);
add(dp[i+1][j+1][price][ty],dp[i][j][cost][ty]*(j-ty+1)%MOD);
add(dp[i+1][j-1][price][ty],dp[i][j][cost][ty]*(j-1)%MOD);
if(ty<2){
add(dp[i+1][j][price][ty+1],dp[i][j][cost][ty]*(2-ty)%MOD);
add(dp[i+1][j+1][price][ty+1],dp[i][j][cost][ty]*(2-ty)%MOD);
}
}
}
}
}
REP(i,k+1)add(ans,dp[n][1][i][2]);
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... |