[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的更多相关文章

  1. [Codeforces626F] Group Projects (DP)

    Group Projects Description There are n students in a class working on group projects. The students w ...

  2. Codeforces 626F Group Projects(滚动数组+差分dp)

    F. Group Projects time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  3. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  4. 【CodeForces】626 F. Group Projects 动态规划

    [题目]F. Group Projects [题意]给定k和n个数字ai,要求分成若干集合使得每个集合内部极差的总和不超过k的方案数.n<=200,m<=1000,1<=ai< ...

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

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

  7. Codeforces 626F Group Projects (DP)

    题目链接  8VC Venture Cup 2016 - Elimination Round 题意  把$n$个物品分成若干组,每个组的代价为组内价值的极差,求所有组的代价之和不超过$k$的方案数. ...

  8. DP的序--Codeforces626F. Group Projects

    $n \leq 200$个数,$ \leq 500$,$K \leq 1000$代价内的数字分组有多少?一个分组的代价是分成的每个小组的总代价:一个小组的代价是极差. 问的极差那就从极入手嘛.一个小组 ...

  9. [Codeforces 626F]Group Projects

    题目大意: 给定\(n\)个数\(a[1]\sim a[n]\),让你把它分为若干个集合,使每个集合内最大值与最小值的差的总和不超过\(K\).问总方案数. 解题思路: 一道很神的dp题. 首先将数进 ...

随机推荐

  1. [BZOJ 3039&洛谷P4147]玉蟾宫 题解(单调栈)

    [BZOJ 3039&洛谷P4147]玉蟾宫 Description 有一天,小猫rainbow和freda来到了湘西张家界的天门山玉蟾宫,玉蟾宫宫主蓝兔盛情地款待了它们,并赐予它们一片土地. ...

  2. 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)

    题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...

  3. Balanced and stabilized quicksort method

    The improved Quicksort method of the present invention utilizes two pointers initialized at opposite ...

  4. HttpURLConnection传json

    private static String sendToWangTing(DataRow dataRow) throws IOException{ String ip = Configuration. ...

  5. sicily 1193. Up the Stairs

    Time Limit: 1sec    Memory Limit:32MB  Description John is moving to the penthouse of a tall sky-scr ...

  6. Deploy Openstack with RDO and Change VNC console to Spice

    Deploy Openstack with RDO and Change VNC console to Spice host os: centOS 7 server config network an ...

  7. selenium grid应用1-多浏览器执行用例

    driver =webdriver.Remote(command_executor=’http://127.0.0.1:4444/wd/hub’, desired_capabilities=Desir ...

  8. curl 发送请求的时候报错

    AWS HTTP error: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see ...

  9. syslog日志格式解析

    在网上搜的文章,写的很全乎.摘抄如下,供大家参考学习 1.介绍 在Unix类操作系统上,syslog广泛应用于系统日志.syslog日志消息既可以记录在本地文件中,也可以通过网络发送到接收syslog ...

  10. python 面试

    知识总结 面试(一)