湖南国庆模拟赛day1 分组

时间:2023-03-08 23:31:16
湖南国庆模拟赛day1 分组

题目大意:
给你一个n个数的数列s,要对这些数进行分组,当有任意两个数在一种方案在一起而在另一种方案中不在一起算是两种不同的方案,一个组的“不和谐程度”为组内数的极差,如果只有一个人的话,此组的不和谐程度为0,求有多少种分组方式,使所有组的不和谐程度不超过k?

数据范围

1<=n<=200,0<=k<=1000,1<=si<=500

样例

input1

4 5

1 3 5 7

output1

9

input2

5 6

1 4 5 8 9

output2

20

/*
排序,设状态为i,j,k,分别表示前i个数还有j组未充满,不和谐程度为k的方案数,分四种情况讨论:这个数自成一组、这个数为最小值开一个2个数以上的组,把这个数填到别的组中去,把这个数作为最大值填到别的组中去,如果单纯计算k,那么复杂度o(n^2*sumk),显然超时,可以用差分的办法去处理这个极差,这样复杂度o(n^2*k)
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int mod = ;
const int maxn = ,maxm = ;
ll n,m,s[maxn],f[][maxn][maxm],cur;
int read(){
char ch=getchar();
int x=,f=;
while(!(ch>=''&&ch<='')){if(ch=='-')f=-;ch=getchar();};
while(ch>=''&&ch<=''){x=x*+(ch-'');ch=getchar();};
return x*f;
}
int main(){
n = read();
m = read();
for(int i = ;i <= n;i++)s[i] = read();
sort(s+,s++n);
f[][][] = f[][][] = ;
ll tv = ,tk = ;
for(int i = ;i <= n;i++){
for(int j = ;j <= n;j++){
for(int k = ;k <= m;k++){
tv = f[cur][j][k];
f[cur][j][k] = ;
if(!tv) continue;
tk = (s[i]-s[i-])*j + k;
if(tk > m) continue;
f[cur^][j][tk] = (f[cur^][j][tk] + tv) % mod;
f[cur^][j+][tk] = (f[cur^][j+][tk] + tv) % mod;
if(j) f[cur^][j-][tk] = (f[cur^][j-][tk] + (tv * j) % mod) % mod;
f[cur^][j][tk] = (f[cur^][j][tk] + (tv * j) % mod) % mod;
}
}
cur ^= ;
}
ll ans = ;
for(int i = ;i <= m;i++) ans = (ans + f[cur][][i]) % mod;
cout<<ans;
return ;
}