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. hdu2055

    #include <stdio.h> int init(char a){ if(a>='a'&&a<='z'){ ); }; } int main(){ int ...

  2. 【drp 12】再识转发和重定向:SpringMVC无法跳转页面

    最近再使用SpringMVC进行页面跳转的时候,不知道发生了什么,始终都无法正确跳转.后来问题解决了,发现是对于转发和重定向没有能很好的理解,以此写篇博客,权当做积累了! 声明:本博客的所有代码,均为 ...

  3. 12.jsp概述及指令

    JSP全名是Java Server Page,它是建立在Servlet规范之上的动态网页开发技术.在JSP文件中,HTML代码与Java代码共同存在.Html代码用来实现网页中静态内容的显示,Java ...

  4. Kubernetes对象

    Kubernetes对象 在之前的文章已经讲到了很多Kubernets对象,包括pod,service,deployment等等.Kubernets对象是一种持久化,表示集群状态的实体.它是一种声明式 ...

  5. BZOJ 1855 [Scoi2010]股票交易 ——动态规划

    DP方程是比较简单的,主要有三种:什么都不做.买入.卖出. 发现买入卖出都是$\Theta (n^3)$但是转移方程都是线性的,而且决策和当前的情况是分开的. 所以可以单调队列优化. 复杂度$\The ...

  6. cf493E Vasya and Polynomial

    Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...

  7. STL学习笔记(三) 关联容器

    条款19:理解相等(equality)和等价(equivalence)的区别 相等的概念是基于 operator== 的,如果 operator== 的实现不正确,会导致并不实际相等等价关系是以&qu ...

  8. hdu 4883

    简单题,当时竟然没有敲出来╮(╯▽╰)╭... 方法:每个时间点排序从小到大排序,之后扫一遍即可:是进的时间点就加人,反之出人.更新最大值即可....囧... #include<iostream ...

  9. mysql PROCEDURE ANALYSE() 用法

    PROCEDURE ANALYSE() 会让 MySQL 帮你去分析你的字段和其实际的数据,并会给你一些有用的建议.只有表中有实际的数据,这些建议才会变得有用,因为要做一些大的决定是需要有数据作为基础 ...

  10. 深入GCD(五):资源竞争

    概述我将分四步来带大家研究研究程序的并发计算.第一步是基本的串行程序,然后使用GCD把它并行计算化.如果你想顺着步骤来尝试这些程序的话,可以下载源码.注意,别运行imagegcd2.m,这是个反面教材 ...