博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU2049 不容易系列之(4)——考新郎
阅读量:4136 次
发布时间:2019-05-25

本文共 904 字,大约阅读时间需要 3 分钟。

Problem Description
国庆期间,省城HZ刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:
首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;
然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.
最后,揭开盖头,如果找错了对象就要当众跪搓衣板...
看来做新郎也不是容易的事情...
假设一共有N对新婚夫妇,其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能.
 

Input
输入数据的第一行是一个整数C,表示测试实例的个数,然后是C行数据,每行包含两个整数N和M(1<M<=N<=20)。
 

Output
对于每个测试实例,请输出一共有多少种发生这种情况的可能,每个实例的输出占一行。
 

Sample Input
22 23 2
 

Sample Output
13
 
错排问题:
#include 
using namespace std;_int64 dp[55];_int64 factor[21];int N,M;_int64 jie(int n){ if(n==1)return 1; if(factor[n])return factor[n]; factor[n]=n*jie(n-1); return factor[n];}int main(){ freopen("C:\\in.txt","r",stdin); memset(factor,0,sizeof(factor)); dp[1]=0; dp[2]=1; for(int i=3;i<21;i++) dp[i]=(i-1)*(dp[i-1]+dp[i-2]); jie(20); factor[0]=1; factor[1]=1; int C; scanf("%d",&C); while(C--){ scanf("%d %d",&N,&M); printf("%I64d\n",factor[N]/factor[N-M]/factor[M]*dp[M]); } return 0;}

转载地址:http://sdvvi.baihongyu.com/

你可能感兴趣的文章
iWatch报错: Authorizationsession time out
查看>>
X-code7 beta error: warning: Is a directory
查看>>
Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.
查看>>
X-code beta 开发iWatch项目,运行没有错误,但是某些操作一点就崩,而且找不错误的原因场景一
查看>>
Xcode 报错: Extra argument in call
查看>>
iTunes Connect 上传APP报错: Communication error. please use diagnostic mode to check connectivity.
查看>>
#import <Cocoa/Cocoa.h> 报错 Lexical or Preprocessor Issue 'Cocoa/Cocoa.h' file not found
查看>>
`MQTTClient (~> 0.2.6)` required by `Podfile`
查看>>
X-Code 报错 ld: library not found for -lAFNetworking
查看>>
Bitcode
查看>>
If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
查看>>
3.5 YOLO9000: Better,Faster,Stronger(YOLO9000:更好,更快,更强)
查看>>
iOS菜鸟学习--如何避免两个按钮同时响应
查看>>
How to access the keys in dictionary in object-c
查看>>
iOS菜鸟学习—— NSSortDescriptor的使用
查看>>
hdu 3787 hdoj 3787
查看>>
hdu 3790 hdoj 3790
查看>>
hdu 3789 hdoj 3789
查看>>
hdu 3788 hdoj 3788
查看>>
zju 1003 zoj 1003
查看>>