[CF626F]Group Projects
[CF626F]Group Projects
题目大意:
有一个长度为\(n(n\le200)\)的数列\(\{A_i\}\),将其划分成若干个子集,每个子集贡献为子集\(\max-\min\)。求子集贡献和\(\le m(m\le1000)\)的划分方案数。
思路:
将每个数看成数轴上的点,原题中的子集贡献和就是在这些点中,每个点作为至多一个线段的端点,所有线段长度之和(同一线段的两个端点可以相同)。
考虑动态规划,将\(\{A_i\}\)排序,用\(f[i][j][k]\)表示用了前\(i\)个点,\(j\)条线段只确定了一个端点,总贡献为\(k\)的方案数。
用\(t=(A_{i+1}-A_i)\times j\),转移方程为:
- \(f[i+1][j][k+t]+=f[i][j][k]\)(该点自己作为线段的两个端点)
- \(f[i+1][j][k+t]+=f[i][j][k]\times j\)(该点作为其它线段的一部分,但不作为端点)
- \(f[i+1][j+1][k+t]+=f[i][j][k]\)(该点作为一条线段的起点)
- \(f[i+1][j-1][k+t]+=f[i][j][k]\times j\)(该点作为某条线段的终点)
时间复杂度\(\mathcal O(n^2m)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<functional>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
typedef long long int64;
const int N=201,M=1001,mod=1e9+7;
int a[N],f[N][N][M];
int main() {
const int n=getint(),m=getint();
for(register int i=1;i<=n;i++) a[i]=getint();
std::sort(&a[1],&a[n]+1);
f[0][0][0]=1;
for(register int i=0;i<n;i++) {
for(register int j=0;j<=n;j++) {
const int t=(a[i+1]-a[i])*j;
for(register int k=0;k<=m-t;k++) {
(f[i+1][j][k+t]+=(int64)f[i][j][k]*(j+1)%mod)%=mod;
if(j!=n) (f[i+1][j+1][k+t]+=f[i][j][k])%=mod;
if(j!=0) (f[i+1][j-1][k+t]+=(int64)f[i][j][k]*j%mod)%=mod;
}
}
}
int ans=0;
for(register int i=0;i<=m;i++) (ans+=f[n][0][i])%=mod;
printf("%d\n",ans);
return 0;
}
[CF626F]Group Projects的更多相关文章
- [Codeforces626F] Group Projects (DP)
Group Projects Description There are n students in a class working on group projects. The students w ...
- Codeforces 626F Group Projects(滚动数组+差分dp)
F. Group Projects time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题
F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...
- 【CodeForces】626 F. Group Projects 动态规划
[题目]F. Group Projects [题意]给定k和n个数字ai,要求分成若干集合使得每个集合内部极差的总和不超过k的方案数.n<=200,m<=1000,1<=ai< ...
- 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 ...
- Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****
F. Group Projects There are n students in a class working on group projects. The students will div ...
- Codeforces 626F Group Projects (DP)
题目链接 8VC Venture Cup 2016 - Elimination Round 题意 把$n$个物品分成若干组,每个组的代价为组内价值的极差,求所有组的代价之和不超过$k$的方案数. ...
- DP的序--Codeforces626F. Group Projects
$n \leq 200$个数,$ \leq 500$,$K \leq 1000$代价内的数字分组有多少?一个分组的代价是分成的每个小组的总代价:一个小组的代价是极差. 问的极差那就从极入手嘛.一个小组 ...
- [Codeforces 626F]Group Projects
题目大意: 给定\(n\)个数\(a[1]\sim a[n]\),让你把它分为若干个集合,使每个集合内最大值与最小值的差的总和不超过\(K\).问总方案数. 解题思路: 一道很神的dp题. 首先将数进 ...
随机推荐
- 【洛谷 P1501】 [国家集训队]Tree II(LCT)
题目链接 Tree Ⅱ\(=\)[模板]LCT+[模板]线段树2.. 分别维护3个标记,乘的时候要把加法标记也乘上. 还有就是模数的平方刚好爆\(int\),所以开昂赛德\(int\)就可以了. 我把 ...
- 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- textarea输入框随内容撑开高度
原文链接 方法一(jquery): $('textarea').each(function () { this.setAttribute('style', 'height:' + (this.scr ...
- CSS实现箭头效果
有时候网页中使用箭头以增强效果,一般的做法是使用图片,今天我们使用CSSCSS来实现“箭头效果”,使用CSS我们必须兼容所有浏览器(IE6.7.8.9.10.+),Chrome,Firefox,Ope ...
- Mysql储存过程6: in / out / inout
in 为向函数传送进去的值 out 为函数向外返回的值 intout 传送进去的值, 并且还返回这个值 )) begin then select 'true'; else select 'false' ...
- python基础之上下文管理器
前言 关于计算器运行的上下文的概念,我的理解也不是很深:按我的理解就是程序在运行之前,其所需要的资源,运行环境等都会被序列化,然后加入到CPU的任务队列中,等待调度系统分配时间片执行.下面谈谈pyth ...
- 分布式队列Celery入门
Celery 是一个简单.灵活且可靠的,处理大量消息的分布式系统,并且提供维护这样一个系统的必需工具.它是一个专注于实时处理的任务队列,同时也支持任务调度.Celery 是语言无关的,虽然它是用 Py ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
- 用于启动 Windows Phone 8 内置应用的 URI 方案
本主题列出了可用于启动内置应用的 URI 方案.许多内置于 Windows Phone 的应用,都可以通过调用 LaunchUriAsync(Uri) 和传入一个使用与要启动应用相关的方案的 URI, ...
- plsql实例精讲部分笔记
转换sql: create or replace view v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,mo ...