不容易系列之(4)——考新郎 hdu2049 递推,错排,组合数
2013-01-22 10:06
274 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2049
组合数源自于杨辉三角形,应该是一种非常基本的递推。
组合数的性质 C(M-1,N-1)+C(M-1,N)=C(M,N)
顺便复习一下,C(M,N)= m!/(n!*(m-n)!) A(M,N) = m!/n!
组合数源自于杨辉三角形,应该是一种非常基本的递推。
组合数的性质 C(M-1,N-1)+C(M-1,N)=C(M,N)
顺便复习一下,C(M,N)= m!/(n!*(m-n)!) A(M,N) = m!/n!
#include <iostream> using namespace std; #define N 25 __int64 a ,b ; void f1(){ a[1]=0; a[2]=1; int i; for (i=3;i<N;i++) a[i]=(i-1)*(a[i-2]+a[i-1]); } void f2(){ int i,j; memset(b,0,sizeof(b)); b[0][0]=1; for (i=0;i<N;i++) b[i][0]=1; for (i=1;i<N;i++) for (j=1;j<=i;j++) b[i][j]=b[i-1][j-1]+b[i-1][j]; } int main(){ int n,m,c; scanf("%d",&c); f1(); f2(); while (c--){ scanf("%d%d",&n,&m); printf("%I64d\n",a[m]*b [m]); } return 0; }
相关文章推荐
- HDU2049 不容易系列之(4)——考新郎【递推】
- hdu2049 不容易系列之(4)——考新郎 错排+组合 一共有N对新婚夫妇,N个新娘随机坐成一排,每个新郎只能选一个, 其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能.
- HDU2049 不容易系列之(4)——考新郎 错排问题
- hdu2049不容易系列之(4)——考新郎
- 2049 不容易系列之(4)——考新郎【错排+排列组合】
- 2049不容易系列之(4)——考新郎(递推)(错排+组合数)
- YT03-递推求解课后题目-1006 不容易系列之(4)——考新郎-(6.7日-烟台大学ACM预备队解题报告)
- HDU2049_不容易系列之(4)——考新郎
- hdoj 2049 不容易系列之(4)——考新郎 【全错位排列】【组合数】
- HDU 2049 不容易系列之(4)——考新郎 (递推,含Cmn公式)
- hduoj2049,不容易系列之(4)——考新郎,递推题,用到排列组合的一些知识
- hdu2049 不容易系列之(4)——考新郎(全错排,组合数)
- HDU 2049 不容易系列之(4)——考新郎(错排)(递推)
- 不容易系列之(4)——考新郎[HDU2049]
- hdu2049 不容易系列之(4)——考新郎
- HDU2049 不容易系列之(4)——考新郎
- hdu2049 不容易系列之(4)——考新郎
- HDOJ 2049 不容易系列之(4)——考新郎【错排 组合数】
- hdu 2049 不容易系列之(4)——考新郎 (错排递推)
- HDU 不容易系列之(4)——考新郎(组合错排)