【HDOJ】2049 不容易系列之(4)——考新郎
与2048非常类似,在2048的基础上考虑组合情况即可。比较简单,但要注意乘法溢出。
#include <stdio.h> #define MAXNUM 22 unsigned long long tb[MAXNUM] = {1,0,1}; unsigned long long factorial[MAXNUM] = {1,1,2}; int main() { int case_n, n, m; int i; scanf("%d", &case_n); for (i=3; i<MAXNUM; ++i) { tb[i] = (i-1) * (tb[i-1] + tb[i-2]); factorial[i] = factorial[i-1] * i; } while (case_n--) { scanf("%d %d", &n, &m); printf("%I64u\n", factorial[n]/(factorial[m]*factorial[n-m])*tb[m]); } return 0; }