Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****
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.
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.
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.
3 2
2 4 5
3
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*****的更多相关文章
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 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 + ...
- 8VC Venture Cup 2016 - Elimination Round
在家补补题 模拟 A - Robot Sequence #include <bits/stdc++.h> char str[202]; void move(int &x, in ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- 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 ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分
E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...
- 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 ...
随机推荐
- CF802D
D. Marmots (easy) time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- [UOJ#122][NOI2013]树的计数
[UOJ#122][NOI2013]树的计数 试题描述 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的 DFS 序以及 BFS 序.两棵不同的树的 DFS 序 ...
- NOJ1203 最多约数问题 [搜索 数论]
传送门 njczy2010 1203 Accepted 79MS 1400K 2321Byte G++ 2015-01-25 13:14:25.0 最多约数问题 时间限制(普通/Java) : 2 ...
- 2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683
本文原创于 2014-02-12 09:26. 今复习之用,有新体会,故重新编辑. 2014-02-12 09:26: 2-sat之第二斩!昨天看了半天论文(赵爽的和俉昱的),终于看明白了!好激动有 ...
- 洛谷P2058 仪仗队
P2058 仪仗队 24通过 34提交 题目提供者shengmingkexue 标签数论(数学相关) 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目描述 作为体育委员,C君 ...
- 深究Spring中Bean的生命周期
前言 这其实是一道面试题,是我在面试百度的时候被问到的,当时没有答出来(因为自己真的很菜),后来在网上寻找答案,看到也是一头雾水,直到看到了<Spring in action>这本书,书上 ...
- 解决本地调用office组件成功,但是发布到IIS中出现的错误(检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失败)
在C#操作word或者Excel,我们可能会用到微软内置的COM组件,会出现很多问题. 如:在本地调试导出Excel没有问题,发布到IIS就有问题了,检测到的异常: 我们会发现在iis上运行的程序,没 ...
- c++引用和const 用法 数组 指针
非const引用,只能用object为其赋值: <c++primer>P52 而const引用则可以用临时变量为其赋值: 如: const int &r = 32://可以 int ...
- vmware Unable to open kernel device "\\.\Global\vmx86": The system cannot find the file 的解决方法
https://communities.vmware.com/thread/245800?start=0&tstart=0 I have exactly same issue. I star ...
- VS2013 update4+Cocos2d-x 3.7 Win8下安装方法及配置
1.安装VS 2013 update4 7个G.自己就去网上找吧,一大堆,密钥问度娘. 2.安装及配置python 2.x 这里注意,一定要下载python 3.0下面的版本号. 配置:进行环境变量配 ...