您的位置:首页 > 其它

不容易系列之(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!

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: