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
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 will be four integers n,r,k,m.We assume that they are all between 1 and 1000.
5 2 3 2
6HintSample 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.
解题思路:
这题考的是排列组合
(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;
}
版权声明:欢迎关注我的博客,本文为博主toyking原创文章,未经博主允许不得转载。
HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)的更多相关文章
- hdu 4045 Machine scheduling [ dp + 斯特林数]
传送门 Machine scheduling Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 4045 Machine scheduling --第二类Strling数
题意: n个数(1~n)取出r个数,取出的数相差要>=k, 然后分成m个可空组,问有多少种情况. 解法: 先看从n个数中取r个相差>=k的数的方法数,可以发现 dp[i][j] = dp[ ...
- BZOJ4559 JLOI2016成绩比较(容斥原理+组合数学+斯特林数)
容斥一发改为计算至少碾压k人的情况数量,这样对于每门课就可以分开考虑再相乘了.剩下的问题是给出某人的排名和分数的值域,求方案数.枚举出现了几种不同的分数,再枚举被给出的人的分数排第几,算一个类似斯特林 ...
- P6620-[省选联考2020A卷]组合数问题【组合数学,斯特林数】
正题 题目链接:https://www.luogu.com.cn/problem/P6620 题目大意 给出\(n,x,p,m\)和一个\(m\)次多项式\(f\)求 \[\sum_{k=0}^nf( ...
- bzoj 2159 Crash 的文明世界 && hdu 4625 JZPTREE ——第二类斯特林数+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 学习材料:https://blog.csdn.net/litble/article/d ...
- hdu 2643 rank 第二类斯特林数
题意:给定n个人,要求这n个人的所有可能排名情况,可以多个人并列(这个是关键). 题解:由于存在并列的问题,那么对于n个人,我们最多有n个排名,枚举一下1~n,累加一下就好.(注意这里是变种的斯特林数 ...
- 蓝桥杯 问题 1110: 2^k进制数 (排列组合+高精度巧妙处理)
题目链接 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2 ...
- 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)
题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...
- bzoj 2159 Crash 的文明世界 & hdu 4625 JZPTREE —— 第二类斯特林数+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 使用公式:\( n^{k} = \sum\limits_{i=0}^{k} S(k,i ...
随机推荐
- .Net魔法堂:史上最全的ActiveX开发教程——发布篇
一. 前言 接着上一篇<.Net魔法堂:史上最全的ActiveX开发教程——开发篇>,本篇讲述如何发布我们的ActiveX. 二.废话少讲,马上看步骤! 1. 打包 C#开发的Activ ...
- UnityShader快速上手指南(三)
简介 这一篇还是一些基本的shader操作:裁剪.透明和法向量的应用 (纠结了很久写不写这些,因为代码很简单,主要是些概念上的东西) 先来看下大概的效果图:(从左到右依次是裁剪,透明,加了法向量的透明 ...
- NopCommerce中的单例
项目中经常会遇到单例的情况.大部分的单例代码都差不多像这样定义: internal class SingletonOne { private static SingletonOne _singleto ...
- 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复
[源码下载] 与众不同 windows phone (47) - 8.0 其它: 锁屏信息和锁屏背景, 电池状态, 多分辨率, 商店, 内置协议, 快速恢复 作者:webabcd 介绍与众不同 win ...
- C# 快速反射 IL
public class FastInvoke { public delegate object FastInvokeHandler(object target, object[] paramters ...
- JMS学习(一)基本概念
这两天面试了一两个公司,由于简历中的最近一个项目用到了JMS,然而面试官似乎对这个很感兴趣,所以都被问到了,但可惜的是,我除了说我们使用了JMS外,面对他们提出的一些关于JMS的问题,我回答得相当差, ...
- 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- mysql performance_schema/information_schema授权问题
mysql> grant all on performance_schema.* to 'testuser'@'%';ERROR 1044 (42000): Access denied for ...
- nodejs连接mysql并进行简单的增删查改
最近在入门nodejs,正好学习到了如何使用nodejs进行数据库的连接,觉得比较重要,便写一下随笔,简单地记录一下 使用在安装好node之后,我们可以使用npm命令,在项目的根目录,安装nodejs ...
- JS中检测数据类型的四种方法
1.typeof 用来检测数据类型的运算符->typeof value->返回值首先是一个字符串,其次里面包含了对应的数据类型,例如:"number"."st ...