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. 【Luogu】P2158仪仗队(欧拉函数)

    题目链接 首先来介绍欧拉函数. 设欧拉函数为f(n),则f(n)=1~n中与n互质的数的个数. 欧拉函数有三条引论: 1.若n为素数,则f(n)=n-1; 2.若n为pa,则f(n)=(p-1)*(p ...

  2. poj1930 数论

    Dead Fraction Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1258   Accepted: 379 Desc ...

  3. Vxlan简介

    1.为什么需要Vxlan 1.什么是VXLAN VXLAN(Virtual eXtensible LAN可扩展虚拟局域网),是一种mac in UDP技术.传统的二层帧被封装到了UDP的报文中,通过U ...

  4. 洛谷 P 3371 单元最短路

    题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输入格式: 第一行包含三个整数N.M.S,分别表示点的个数.有向边的个数.出发点的编号. 接下来M行每行包含三 ...

  5. 【BZOJ1500】维修数列(splay)

    题意: 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目.第2行包含N个数字,描述初始时的数列.以下M行,每行一条命令,格式参见问题描述中的 ...

  6. angular中的this指向问题

    this是指向当前$scope的. 例如在ng-click的使用中,this是指向当前的$scope而并不是dom元素的. 我们可以使用this的一些方法和属性 我们打印一下this就会发现,this ...

  7. asp.net在IE10下事件丢失排错经过

    下午看一篇文章,感觉对以后自己开发有点用途,摘抄下来. 原文出处:http://www.cnblogs.com/weapon/archive/2013/06/23/3150584.html 最近项目中 ...

  8. Python入门--13--爬虫一

    URL的格式一般为(带方括号的是可选的): protocol://hostname[:port]/path/[;parameters][?query]#fragment URL由三部分组成: 第一部分 ...

  9. Virnish使用

    缓存基础原理 程序具有局部性 时间局部性 空间局部性 key-value 形式存储数据 key 访问路径.URL.hash value web content 命中率 hit/(hit+miss) 文 ...

  10. html--添加、删除滚动条

    1:若想给div添加滚动条: style="overflow-y:scroll";(添加纵向滚动条) style="overflow-x:scroll";(添加 ...