Kevin's Problem

题目连接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4921

Description

In his applied probability class, Kevin learned about the Secretary Problem.
There are N applicants applying for secretary position in a company. The applicants are
interviewed by a hiring manager one by one in arbitrary order. During the interview, the
manager can rank the applicant’s quality uniquely relative to all applicants which have been
interviewed so far, but he has no idea of the quality of applicants yet to be interviewed.
The decision whether the manager should hire or reject the applicant must be done right
after the interview ended (before he starts an interview with other applicant) and cannot be
changed, i.e. once rejected, that particular applicant cannot be considered anymore. There
is only one position available, so what is the best decision strategy for this problem?
One reasonable strategy is: reject the first K applicants and hire the first remaining applicant who
is better than all previous interviewed applicants, or hire the last one if there is no such applicant.
Unfortunately, Kevin did not pay a full attention in his class. He misunderstood the strategy;
instead of “. . . hire the first remaining applicant who is better than all previous interviewed applicants
. . . ”, he thought it is “. . . hire the first remaining applicant who is better than the (immediate) previous
interviewed applicant . . . ”. Let’s call this variation as Kevin’s strategy.
Given N, K, and p determine in how many ways (interview order) such that the applicant whose
rank is p among all applicants will be selected by Kevin’s strategy. For example, let N = 4, K = 2,
and p = 2. Among all permutation of 1 . . . N, there are only 7 possible permutation such that the 2nd
rank applicant is selected by Kevin’s strategy.
• 1, 3, 2, 4 — 2 is selected because it’s better than 3.
• 1, 3, 4, 2 — 2 is selected because 4 is worse than 3, and 2 is better than 4.
• 1, 4, 2, 3
• 3, 1, 4, 2
• 3, 4, 2, 1
• 4, 1, 3, 2
• 4, 3, 2, 1
Note that the first 2 applicants will not be hired in this example (K = 2). Clearly, the 2nd rank
applicant will not be selected in any permutation where she appears in the first K.
An applicant has a better rank if her rank is higher (smaller number), e.g. 2nd rank is better than
5th.

Input

The first line of input contains an integer T (T ≤ 100) denoting the number of cases. Each case contains
three integers: N, K, and p (2 ≤ N ≤ 500; 1 ≤ K < N; 1 ≤ p ≤ N) as explained in the problem
description above.

Output

For each case, output ‘Case #X: Y ’, where X is the case number starts from 1 and Y is the number
of permutation of 1 . . . N such that the p-th rank applicants is selected by Kevin’s strategy for that
particular case. As this number could be very large, modulo Y by 1,000,000,007.
Explanation for 3rd sample case:
There are 5 applicants and Kevin’s strategy will reject the first 3. 5th rank applicant will be
selected only if she is interviewed last, thus the manager has no choice but to hire her. Among 24
possible permutations where 5th rank applicant appears last, only 12 permutations which make her
hired:
1, 2, 3, 4, 5 2, 1, 3, 4, 5 3, 1, 2, 4, 5 4, 1, 2, 3, 5
1, 3, 2, 4, 5 2, 3, 1, 4, 5 3, 2, 1, 4, 5 4, 2, 1, 3, 5
1, 4, 2, 3, 5 2, 4, 1, 3, 5 3, 4, 1, 2, 5 4, 3, 1, 2, 5
Some examples where 5th rank will not be hired even though she is the last:
1, 2, 4, 3, 5 – 3rd rank will be hired.
1, 4, 3, 2, 5 – 2nd rank will be hired.
3, 2, 4, 1, 5 – 1st rank will be hired.
. . .

Sample Input

4
4 2 2
5 2 3
5 3 5
8 4 2

Sample Output

Case #1: 7
Case #2: 26
Case #3: 12
Case #4: 7890

Hint

题意

有一个公司,有编号为1~n,也是他们能力排名的人来应聘。

公司准备只招一个人,他的招聘采用如下策略:

先排除前k个人,然后再看,如果这个人比前一个人厉害,那就录取。

如果没有人录取的话,那就录取最后一个人。

问你有n个人,现在k个人排除,录取能力为p的人的方案数有多少种。

题解:

数学题,前面k个我们不用管,然后到第p个人,那么第p个人前面的应该是一个能力递减编号递增的序列,然后剩下位置就全排列。

然后这样枚举p的位置,然后搞一波就好了。

代码

#include <bits/stdc++.h>
#define rep(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define drep(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define pb push_back
#define mp make_pair
#define sf scanf
#define pf printf
#define two(x) (1<<(x))
#define clr(x,y) memset((x),(y),sizeof((x)))
#define dbg(x) cout << #x << "=" << x << endl;
#define lowbit(x) ((x)&(-x))
const int mod = 1e9 + 7;
int mul(int x,int y){return 1LL*x*y%mod;}
int qpow(int x , int y){int res=1;while(y){if(y&1) res=mul(res,x) ; y>>=1 ; x=mul(x,x);} return res;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std;inline void up(int & x ,int v){ x += v; if( x >= mod ) x -= mod; }
/*
dp(i , j , k , f)
已经放了 i 个 , 有 j 个比 p 小的已经放了, k -> 前面一个放的是谁 , f 表示 p 放了没有
*/const int maxn = 500 + 15;
int N,K,P,C[maxn][maxn],fac[maxn];void init(){fac[0] = 1;for(int i = 1 ; i < maxn ; ++ i) fac[i] = mul( fac[i - 1] , i );C[0][0] = 1;for(int i = 1 ; i < maxn ; ++ i){C[i][0] = 1;for(int j = 1 ; j <= i ; ++ j) up( C[i][j] ,  C[i - 1][j - 1] + C[i - 1][j] );}
}int A(int n , int m){return mul( fac[n] , qpow( fac[n - m] , mod - 2 ) );
}int main(int argc,char *argv[]){init();int T=read(),cas=0;while(T--){N=read(),K=read(),P=read();int ans = 0;up( ans , A( N - 1 , K - 1 ) );for(int i = K + 1 ; i < N ; ++ i){for(int j = P + 1 ; j <= N ; ++ j){if( j - 2 < 0 || j - 2 < i - K - 1 ) continue;int y = C[ j - 2 ][ i - K - 1 ];up( ans , mul( y , fac[N - i + K - 1] ) );}}pf("Case #%d: %d\n" , ++ cas , ans );}return 0;
}

转载于:https://www.cnblogs.com/qscqesze/p/5734081.html

UVALive 6909 Kevin's Problem 数学排列组合相关推荐

  1. 计算机组装错题整理,数学排列组合部分错题精选.docx

    数学排列组合部分错题精选 数学复习易做易错题选 排列组合易错题正误解析 排列组合问题类型繁多.方法丰富.富于变化,稍不注意,极易出错.本文选择一些在教学中学生常见的错误进行正误解析,以飨读者. 1没有 ...

  2. 【一级讲解】不可思议唤来不可思议β——数学排列组合

    不可思议唤来不可思议β Time Limit: 1 Sec Memory Limit: 128 MB Description In the world line 1.048596% 双叶理央因为&qu ...

  3. 【牛客每日一题】4.16 逆序对 ( 数学 , 排列组合 ,快速幂 , 快速乘 )

    [每日一题]逆序对 链接:https://ac.nowcoder.com/acm/problem/14731 来源:牛客网 题目描述 求所有长度为n的01串中满足如下条件的二元组个数: 设第i位和第j ...

  4. 自编高中数学---排列组合公式推导

    知乎一个竞赛生写的排列组合文章:https://www.zhihu.com/question/26094736 一.排列 ,Permutaion 把n件东西往m个位置里排序,有多少种排法? 记排列方法 ...

  5. C语言-实现数学排列组合里的排列算法

    本文将编写一个函数实现数学排列的功能,采用的办法是递归.具体功能如图所示: 一.函数的讲解 1.1 函数的原型 函数的原型:int** Permutation(int* iarr,int size): ...

  6. 放回c41_数学排列组合C41C43怎么算

    展开全部 C41=C43=(4*3*2)/(3*2*1)=4 . 公式:C(n,m)=A(n,m)∧2/m!=A(n,m)/m!:  C(n,m)=C(n,n-m).(其中n≥m) 组合介绍: 组合是 ...

  7. 程序员的数学--排列组合(2)

    排列 在上一节中,我们罗列了n个事物的所有排法,那么在这一节中我们将从n个事物中取出一部分进行排列 思考题:从5张牌中取出3张进行排列 经过思考,我们可以得出一共有60种方法. 我们像上题种那样从5张 ...

  8. 数学-排列组合的理解

    一.排列 排列是有顺序的排队,从 m 中选择 n 个进行排队,第 1 个有 m-0 种选择,第 2 个有 m-1 种选择,自然的,第 n 个有 m-(n-1) 种选择.因为有顺序,可以看出前面的选择, ...

  9. 高中数学排列组合二项定理经典题型汇编(名师总结)

    今天老师给同学们整理出高中数学二项式定理相关内容,该题在高考中常以选择题或填空题形式出现,难度为容易或中等.下面就一起来看看二项式定理主干知识,以及常考题型~ 一.知识点梳理 二.经典题型汇总 今天的 ...

最新文章

  1. 仅凭一部iPhone手机,打造现实版元宇宙
  2. excel去掉超链接
  3. 曼哈顿距离(坐标投影距离之和)d(i,j)=|X1-X2|+|Y1-Y2|.
  4. 研究生应当具备的三种基本技能
  5. Redis学习笔记1-安装配置
  6. MC缓存序列化php,PHP serialize()序列化的使用
  7. PHP最全笔记(三)(值得收藏,不时翻看一下)
  8. Windows可以往外ping,外部却ping不通本机
  9. 科技文献检索(七)——检索工具
  10. 用Python实现一个电影订票系统
  11. label confusion learning to enhance text classification models
  12. Android三级缓存机制工具类的实现
  13. 也来说说电影《少年班》中周知庸问王大法的问题
  14. maya2020 redshift3.0.31demo版安装方法。
  15. win10sas安装教程_win10s是什么版本_windows10s版本的特性图文教程
  16. 网络原理4 数据链路层
  17. 让我差点中计的电话诈骗套路!|凹凸日常
  18. JS Boolean 初始值
  19. java钣金,钣金展开计算(铆工大师)软件注册
  20. python3 pyQt5之listWidget控件的高级运用--将多种控件组合插入其中一行

热门文章

  1. SpringBoot工程不注册到Eureka上
  2. Command line is too long. Shorten command line for Doc.generateAsciiDocs or
  3. IDEA去除掉虚线,波浪线,和下划线实线的方法
  4. loadrunner提示:Cannot save the license information because acceses to the registry is denied
  5. JavaScript中的对象学习笔记(属性操作)
  6. 构建之法阅读笔记之三
  7. 利用BitLocker和VHD实现共享文件加密
  8. sqoop 把 hdfs 和关系型数据库 (mysql等)互导
  9. 解决思维导图软件Mindmanager Mindjet连接出错
  10. 双活架构保服务24小时在线