求N!的另一种方法

 1 // File Name: text.cpp
 2 // Author: sheng
 3 // Created Time: 2013年05月09日 星期四 20时02分44秒
 4 
 5 #include <iostream>
 6 #include <stdio.h>
 7 #include <math.h>
 8 #include <string.h>
 9 using namespace std;
10 
11 const long long max_n = 1 << 20;
12 long long f[max_n];
13 long long MOD = 1e9+7;
14 
15 int main()
16 {
17     int n;
18     while (~scanf ("%d", &n))
19     {
20         memset (f, 0, sizeof (f));
21         f[0] = 1;
22         for (long long i = 1; i < 1<<n; i ++)
23         {
24             long long t = i;
25             while (t > 0)
26             {
27                 f[i] += f[i^(t&-t)];
28                 f[i] %= MOD;
29                 t -= t&(-t);
30             }
31         }
32         cout << f[(1<<n) - 1] <<endl;
33     }
34     return 0;
35 }
原文地址:https://www.cnblogs.com/shengshouzhaixing/p/3069956.html