HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

Machine scheduling

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1000    Accepted Submission(s): 363

Problem Description

A Baidu’s engineer needs to analyze and process large amount of data on machines every day. The machines are labeled from 1 to n. On each day, the engineer chooses r machines to process data. He allocates the r machines to no more than m groups ,and if the
difference of 2 machines‘ labels are less than k,they can not work in the same day. Otherwise the two machines will not work properly. That is to say, the machines labeled with 1 and k+1 can work in the same day while those labeled with 1 and k should not
work in the same day. Due to some unknown reasons, the engineer should not choose the allocation scheme the same as that on some previous day. otherwise all the machines need to be initialized again. As you know, the initialization will take a long time and
a lot of efforts. Can you tell the engineer the maximum days that he can use these machines continuously without re-initialization.

Input

Input end with EOF.

Input will be four integers n,r,k,m.We assume that they are all between 1 and 1000.

Output

Output the maxmium days modulo 1000000007.

Sample Input

5 2 3 2

Sample Output

6

Hint

Sample input means you can choose 1 and 4,1 and 5,2 and 5 in the same day.
And you can make the machines in the same group or in the different group.
So you got 6 schemes.
1 and 4 in same group,1 and 4 in different groups.
1 and 5 in same group,1 and 5 in different groups.
2 and 5 in same group,2 and 5 in different groups.
We assume 1 in a group and 4 in b group is the same as 1 in b group and 4 in a group.

Source

The 36th ACM/ICPC
Asia Regional Beijing Site —— Online Contest

Recommend

lcy   |   We have carefully selected several similar problems for you:  4049 4047 4050 4048 4042

解题思路:

这题考的是排列组合

(1)首先,要从n个元素编号1~n中选出r个元素来,使得任意两个元素编号相差>=k

解法:先按照 1 k+1 2*k+1 .... (r-1)*k+1 也就是刚好 间隔 k个排列下来

那么 总共n个元素,剩余 n-(r-1)*k-1个元素可以看成空格,极为space,将它们插入这r个元素的r+1个空档中,

这样就能保证枚举了素有的方法数,切满足任意两个元素编号相差>=k的要求

所以这个问题简化为:将space个元素分配到r+1个区域中,可以为空

答案为:stir2[space][r+1],第二类斯特林数

(2)然后,再将选取的r个元素分为不超过g组,枚举想要的组数即可

只需要枚举对应的组数, 1~min(r,g)

转化问题:将n个元素最多分为m个集合,不为空的方案法,插板法,答案为:c[n+m-1][m-1]

解题代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
const int maxn=1010;
int n,r,m,g;

ll c[2*maxn][2*maxn],stir2[maxn][maxn];

void ini(){
    for(int i=1;i<2*maxn;i++){
        c[i][0]=c[i][i]=1;
        for(int j=1;j<i;j++)
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
    }
    for(int i=1;i<maxn;i++){
        stir2[i][0]=0;
        stir2[i][i]=1;
        for(int j=1;j<i;j++)
            stir2[i][j]=((ll)j*stir2[i-1][j]+stir2[i-1][j-1])%mod;
    }
}

ll get1(ll n,ll m){//将n个元素最多分为m个集合,不为空的方案法。
    return c[n+m-1][m-1];
}

ll get2(ll n,ll m){//将n个元素分配到m个区域中,可以为空。
    return stir2[n][m];
}

void solve(){
    int space=n-(r-1)*m-1;
    if(space<0){
        printf("0\n");
        return ;
    }
    ll ans=0;
    //将r个元素分为i组
    for(int i=1;i<=min(r,g);i++){
        ans=(ans+get2(r,i))%mod;
    }
    ans=( ans*get1(space,r+1) )%mod;
    cout<<ans<<endl;
}

int main(){
    ini();
    while(scanf("%d%d%d%d",&n,&r,&m,&g)!=EOF){
        solve();
    }
    return 0;
}
时间: 2024-10-08 11:03:46

HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)的相关文章

hdu 4045 Machine scheduling [ dp + 斯特林数]

传送门 Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1048    Accepted Submission(s): 387 Problem Description A Baidu’s engineer needs to analyze and process large amount of dat

HDU 4045 Machine scheduling (第二类斯特林数+DP)

A Baidu's engineer needs to analyze and process large amount of data on machines every day. The machines are labeled from 1 to n. On each day, the engineer chooses r machines to process data. He allocates the r machines to no more than m groups ,and

HDU 4372 Count the Buildings(组合数学-斯特林数,组合数学-排列组合)

Count the Buildings Problem Description There are N buildings standing in a straight line in the City, numbered from 1 to N. The heights of all the buildings are distinct and between 1 and N. You can see F buildings when you standing in front of the

HDU 4045 Machine scheduling --第二类Strling数

题意: n个数(1~n)取出r个数,取出的数相差要>=k, 然后分成m个可空组,问有多少种情况. 解法: 先看从n个数中取r个相差>=k的数的方法数,可以发现 dp[i][j] = dp[1][j-1] + dp[2][j-1] + ... + dp[i-k][j-1],(dp[i][1] = i)  即维护一个前缀和即可,可以在O(r*n)内得出. 然后n个不同的数分成m个可以空的组,即为第二类Strling数的和 : S[n][1] + S[n][2] + ... + S[n][m]. S

【noi 2.6_9288】&amp;【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度)

题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变形.(推荐阅读:http://www.cnblogs.com/chenhuan001/p/5157133.html).P.S.不知我之前自己推出的公式“C(n,m)*C(2*m,m)/(m+1)*P(n,n)*P(m,m)”是否是正确的. (1)在不考虑m人和n人本身组内的排列时,总方案数为C(m+

HDU 3240 Counting Binary Trees(组合数学-斯特林数,数论-整数快速幂,数论-求逆元)

Counting Binary Trees Problem Description There are 5 distinct binary trees of 3 nodes: Let T(n) be the number of distinct non-empty binary trees of no more than n nodes, your task is to calculate T(n) mod m. Input The input contains at most 10 test

hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理

//昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中没有的质因子 2,存在bi>bi',然后剩下的都是可行解,对于每一个质因子三个数中有两个分别bi,bi',第三个的取值可为[bi,bi'],所以对于每一个质因子共有6(bi-bi')种取法(A(2,3)*(b-a+1)+C(2,3)*2分别为取得值在和不在边界上的情况,特殊:如果bi=bi'就只有一

bzoj 3505 [Cqoi2014]数三角形——排列组合

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题!一定要经常回顾! 那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的gcd-1 真是很妙. https://blog.csdn.net/u012288458/article/details/48624859 https://www.cnblogs.com/Var123/p/5377616.html 然而还可以递推?https://www.cnblogs.com/liu

bzoj 5093 [Lydsy1711月赛]图的价值 NTT+第二类斯特林数

[Lydsy1711月赛]图的价值 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 245  Solved: 128[Submit][Status][Discuss] Description “简单无向图”是指无重边.无自环的无向图(不一定连通). 一个带标号的图的价值定义为每个点度数的k次方的和. 给定n和k,请计算所有n个点的带标号的简单无向图的价值之和. 因为答案很大,请对998244353取模输出. Input 第一行包含两个正整数n,k(