//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD=1000000007;
int n,m;
ll arr[105];
ll memo[105][105][1005][3];
ll dp(ll i,ll j,ll k,ll l){
//processed, num connected, cost, sides
if (k>m) return 0;
if (i==n){
if (j==1 && l==0) return 1;
else return 0;
}
if (memo[i][j][k][l]!=-1) return memo[i][j][k][l];
ll res=0;
//put on a endpoint and touch connected
if (l && j){
res=(res+dp(i+1,j,k+(2*j-2+(l-1))*arr[i],l-1)*l)%MOD;
}
//put on endpoint and dont touch
if (l){
res=(res+dp(i+1,j+1,k+(2*j+(l-1))*arr[i],l-1)*l)%MOD;
}
//touch connected
if (j){
res=(res+dp(i+1,j,k+(2*j-2+l)*arr[i],l)*(2*(j-1)+l))%MOD;
}
//touch nothing
res=(res+dp(i+1,j+1,k+(2*j+l)*arr[i],l)*(j-1+l))%MOD;
//join 2 connected
if (j>1){
res=(res+dp(i+1,j-1,k+(2*j-4+l)*arr[i],l)*(j-1))%MOD;
}
//cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<res<<endl;
return memo[i][j][k][l]=res;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>m;
rep(x,0,n) cin>>arr[x];
sort(arr,arr+n);
rep(x,0,n) arr[x]=arr[x+1]-arr[x];
memset(memo,-1,sizeof(memo));
cout<<dp(0,0,0,2)<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
260404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
260472 KB |
Output is correct |
2 |
Correct |
122 ms |
260424 KB |
Output is correct |
3 |
Correct |
112 ms |
260412 KB |
Output is correct |
4 |
Correct |
119 ms |
260432 KB |
Output is correct |
5 |
Correct |
110 ms |
260540 KB |
Output is correct |
6 |
Correct |
120 ms |
260416 KB |
Output is correct |
7 |
Correct |
122 ms |
260472 KB |
Output is correct |
8 |
Correct |
120 ms |
260420 KB |
Output is correct |
9 |
Correct |
117 ms |
260492 KB |
Output is correct |
10 |
Correct |
121 ms |
260420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
260404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |