F. Group Projects
 

There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i-th student ai minutes to finish his/her independent piece.

If students work at different paces, it can be frustrating for the faster students and stressful for the slower ones. In particular, the imbalance of a group is defined as the maximum ai in the group minus the minimum ai in the group. Note that a group containing a single student has an imbalance of 0. How many ways are there for the students to divide into groups so that the total imbalance of all groups is at most k?

Two divisions are considered distinct if there exists a pair of students who work in the same group in one division but different groups in the other.

Input

The first line contains two space-separated integers n and k (1 ≤ n ≤ 200, 0 ≤ k ≤ 1000) — the number of students and the maximum total imbalance allowed, respectively.

The second line contains n space-separated integers ai (1 ≤ ai ≤ 500) — the time it takes the i-th student to complete his/her independent piece of work.

Output

Print a single integer, the number of ways the students can form groups. As the answer may be large, print its value modulo 109 + 7.

Examples
input
3 2
2 4 5
output
3
Note

In the first sample, we have three options:

  • The first and second students form a group, and the third student forms a group. Total imbalance is 2 + 0 = 2.
  • The first student forms a group, and the second and third students form a group. Total imbalance is 0 + 1 = 1.
  • All three students form their own groups. Total imbalance is 0.

In the third sample, the total imbalance must be 0, so each student must work individually.

题意:

  给n个人, 让我们分成若干组, 每组的价值是最大值减去最小值,所有组价值之和不能超过k

  求方案数

题解:

  这个是一道很强的DP

  我们用dp[i][j][k]表示考虑了前i个数了, 有j个组是开放的(所谓开放指的是只有最小值, 还没有最大值, 还可以进人), 当前值之和为k 的方案数。

  我们先排序, 这样, 对于开放的组, 每次的累加量就都是 j*(a[i] - a[i-1])。

  那么转移的情况要考虑这么几个:

  1. 第i个数单组一组

  2.第i个数新开一组, 作为新组的最小值

  3.第i个数关闭一组, 作为这个组的最大值。

  4.第i个数进入j个组中的某一组。

  提示,要理解差分思想

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = +, M = 1e3+,inf = 2e9,mod = 1e9+; LL dp[][N][M];
int n,m,a[N];
int main() {
scanf("%d%d",&n,&m);
for(int i = ; i <= n; ++i) scanf("%d",&a[i]);
sort(a+,a++n);
dp[][][] = ;
a[] = a[];
int now = ;
for(int i = ; i <= n; ++i) {
now ^= ;
memset(dp[now],,sizeof(dp[now]));
for(int j = ; j <= i; ++j) {
for(int k = ; k <= m; ++k) {
if(dp[now^][j][k] == ) continue; if(j*(a[i]-a[i-])+k > m) break; dp[now][j][j*(a[i]-a[i-])+k] += dp[now^][j][k],dp[now][j][j*(a[i]-a[i-])+k] %= mod;
dp[now][j+][j*(a[i]-a[i-])+k] += dp[now^][j][k],dp[now][j+][j*(a[i]-a[i-])+k] %= mod; if(j)dp[now][j-][k+j*(a[i]-a[i-])] += 1LL*j*dp[now^][j][k],dp[now][j-][k+j*(a[i]-a[i-])]%=mod; dp[now][j][k+j*(a[i]-a[i-])] += 1LL*j*dp[now^][j][k],dp[now][j][k+j*(a[i]-a[i-])] %= mod; }
}
}
LL ans = ;
for(int i = ; i <= m; ++i) {
ans = (ans + dp[now][][i])%mod;
}
printf("%lld\n",ans);
return ;
}

Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  2. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  3. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  4. 8VC Venture Cup 2016 - Elimination Round

    在家补补题   模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...

  5. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  6. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  7. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  8. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  9. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

随机推荐

  1. [uiautomator篇] bluetooth---接口来做

    package com.softwinner.performance.frameratetest; import android.Manifest; import android.bluetooth. ...

  2. CocoaAsyncSocket一个第三方Socket库

    github地址:https://github.com/robbiehanson/CocoaAsyncSocket github上的不完整,cocochina也有demohttp://code4app ...

  3. 【离散化树状数组】Nordic Collegiate Programming Contest G.Galactic Collegiate Programming Contest

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ; struct node { in ...

  4. bzoj [Scoi2016]美味

    [Scoi2016]美味 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 721  Solved: 391[Submit][Status][Discus ...

  5. JavaScript 的时间消耗--摘抄

    JavaScript 的时间消耗 2017-12-24 dwqs 前端那些事儿 随着我们的网站越来越依赖 JavaScript, 我们有时会(无意)用一些不易追踪的方式来传输一些(耗时的)东西. 在这 ...

  6. 系统进程的Watchdog

    编写者:李文栋 /rayleeya http://rayleeya.iteye.com/blog/1963408 3.1 Watchdog简介 对于像笔者这样没玩过硬件的纯软程序员来说,第一次看到这个 ...

  7. 重写enum的valueof方法等

    enum 对象的常用方法介绍 int compareTo(E o)           比较此枚举与指定对象的顺序. Class<E> getDeclaringClass()        ...

  8. android获取手机号

    private String getPhoneNum(){ //与手机建立连接 TelephonyManager tm = (TelephonyManager)getSystemService(Con ...

  9. 洛谷——P1746 离开中山路

    P1746 离开中山路 题目背景 <爱与愁的故事第三弹·shopping>最终章. 题目描述 爱与愁大神买完东西后,打算坐车离开中山路.现在爱与愁大神在x1,y1处,车站在x2,y2处.现 ...

  10. jquery的固定定位效果

    今天做了个固定定位的效果.比如对导航需要进行固定定位效果: 当没有滚动到导航下面,导航正常显示. 当滚动到导航下面,导航就固定到顶部. 这个效果使用了jquery的方法实现,具体思路为: 1)首先获取 ...