CF626F Group Projects
There are n students, each student has a capacity value ai. Now, we students into some groups (an arbitrary number), "disharmony degree" of each set value is the difference between the minimum capacity of the set of student ability value and the maximum capability value students. All of disharmony seek does not exceed the total number of program packets k.
Sample input and output
Input # 1
3 2
2 4 5
Output # 1
3
Input # 2
4 3
7 8 9 10
Output # 2
13
Input # 3
4 0
5 10 20 21
Output # 3
View Code
1
hint:n<=200,k<=1000
sol:
The sort a
note must be a degree of dissonance end value - the value of the starting point, there may be several intermediate non-final non-starting point, you can easily put
dp [i, j, k] i represents the number of front, there are a starting point not match j, k is the number of current total contribution to a program
transfer is made to enumerate the current point starting point, intermediate point and end point
Then it will hang badly, there is something a very pit, it is both a starting point and a point is the end
/ * The sort a note must be a degree of dissonance end value - the value of the starting point, there may be several intermediate non-final non-starting point, can easily put dp [i, j, k] denotes the i-th former number, as well as a starting point not match j, k is the number of current total contribution to a program transfer is made to enumerate the current point starting point, intermediate point, end point and then will hang badly, there is something a very pit, is both a point the starting point is the end point * / #include <bits / STDC ++ H.> the using namespace STD; typedef int LL; inline LL Read () { LL S = 0 ; BOOL F = 0 ; char CH = ' ' ; the while (isdigit (! CH)) {F | = (CH == ' - ' ); CH = getchar ();} the while (isdigit (CH)) = {S (S <<3)+(s<<1)+(ch^48); ch=getchar();} return (f)?(-s):(s); } #define R(x) x=read() inline void write(ll x) { if(x<0) {putchar('-'); x=-x;} if(x<10) {putchar(x+'0'); return;} write(x/10); putchar((x%10)+'0'); } #define W(x) write(x),putchar(' ') #define Wl(x) write(x),putchar('\n') const int Mod=1000000007,N=205; int n,m,a[N]; int dp[2][N][1005]; inline void Ad(int &x,int y) { x+=y; x-=(x>=Mod)?Mod:0; } int main() { freopen("codeforces626F_data.in","r",stdin); int i,j,k,t; R(n); R(m); for(i=1;i<=n;i++) R(a[i]); sort(a+1,a+n+1); dp[t=0][0][0]=1; for(i=1;i<=n;i++) { t^=1; for(j=0;j<=min(i,n>>1);j++) { int oo=a[i]-a[i-1]; for(k=0;k<=m;k++) { dp[t][j][k]=0; if(j&&k>=(j-1)*oo) Ad(dp[t][j][k],dp[t^1][j-1][k-(j-1)*oo]); if(k>=j*oo) Ad(dp[t][j][k],1LL*dp[t^1][j][k-j*oo]*j%Mod); if(k>=(j+1)*oo) Ad(dp[t][j][k],1LL*dp[t^1][j+1][k-(j+1)*oo]*(j+1)%Mod); if(k>=j*oo) Ad(dp[t][j][k],dp[t^1][j][k-j*oo]); } } } int ans=0; for(i=0;i<=m;i++) Ad(ans,dp[t][0][i]); Wl(ans); return 0; }