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
  1. 3 2
    2 4 5
output
  1. 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个组中的某一组。

  提示,要理解差分思想

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #pragma comment(linker, "/STACK:102400000,102400000")
  4. #define ls i<<1
  5. #define rs ls | 1
  6. #define mid ((ll+rr)>>1)
  7. #define pii pair<int,int>
  8. #define MP make_pair
  9. typedef long long LL;
  10. const long long INF = 1e18+1LL;
  11. const double Pi = acos(-1.0);
  12. const int N = +, M = 1e3+,inf = 2e9,mod = 1e9+;
  13.  
  14. LL dp[][N][M];
  15. int n,m,a[N];
  16. int main() {
  17. scanf("%d%d",&n,&m);
  18. for(int i = ; i <= n; ++i) scanf("%d",&a[i]);
  19. sort(a+,a++n);
  20. dp[][][] = ;
  21. a[] = a[];
  22. int now = ;
  23. for(int i = ; i <= n; ++i) {
  24. now ^= ;
  25. memset(dp[now],,sizeof(dp[now]));
  26. for(int j = ; j <= i; ++j) {
  27. for(int k = ; k <= m; ++k) {
  28. if(dp[now^][j][k] == ) continue;
  29.  
  30. if(j*(a[i]-a[i-])+k > m) break;
  31.  
  32. dp[now][j][j*(a[i]-a[i-])+k] += dp[now^][j][k],dp[now][j][j*(a[i]-a[i-])+k] %= mod;
  33. dp[now][j+][j*(a[i]-a[i-])+k] += dp[now^][j][k],dp[now][j+][j*(a[i]-a[i-])+k] %= mod;
  34.  
  35. 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;
  36.  
  37. 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;
  38.  
  39. }
  40. }
  41. }
  42. LL ans = ;
  43. for(int i = ; i <= m; ++i) {
  44. ans = (ans + dp[now][][i])%mod;
  45. }
  46. printf("%lld\n",ans);
  47. return ;
  48. }

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. 2017 Multi-University Training Contest - Team 4

    日常绝望系列 Questionnaire HDU - 6075 In order to get better results in official ACM/ICPC contests, the te ...

  2. shell的brake和continue的用法

    在循环过程中,有时候需要在未达到循环结束条件时强制跳出循环,像大多数编程语言一样,Shell也使用 break 和 continue 来跳出循环. break命令 break命令允许跳出所有循环(终止 ...

  3. mysql5.7.23版本环境配置

    亲身实践安装mysql,用时居然花费了三个小时,在有那么多教程的情况下,依然在不该花费时间的路上浪费了太多时间.希望这篇文章能够帮助大家少走弯路~~ 1.下载我下载的是64位. 2.解压下载之后,我选 ...

  4. Ubuntu 常用命令和一些 tips

    001. ubuntu 解压.tar.xz文件到另一个文件夹:sudo tar -xvJf ***.tar.xz -C /usr/src sudo 超级用户tar [选项...][file]...-x ...

  5. 【JQ同胞遍历】

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Codeforces963D. Frequency of String

    $n \leq 100000$的一文本串,给$m \leq 100000$个询问,每次问一小串在文本串的哪一个最短的子串里出现指定次数.注意,询问串互不相同,且总长度$\leq 100000$. 比赛 ...

  7. MySQL-JDBC Loadbalance深入解析

    背景说明 公司的整个电商系统搭建在华为云上,根据老总的估计,上线3个月之后日订单量会达到百万级别,保守估计3个月之后总订单个数预计会有5千万.MySQL单表达到千万级别,就会出现明显的性能问题.根据如 ...

  8. HDU 4433 locker(12年天津,DP)

    4576 njczy2010 C Accepted 860 KB 140 ms G++ 2063 B 2014-10-16 09:51:19 哎,为啥1000*100*100的复杂度的dp就不敢敲了呢 ...

  9. 标准C程序设计七---06

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  10. msp430项目编程41

    msp430综合项目---红外遥控直流电机调速系统41