Description
Time Limit: 1000ms
Description
Given N distinct elements, how many permutations we can get from all the possible subset of the elements?
Input
The first line is an integer T that stands for the number of test cases.
Then T line follow and each line is a test case consisted of an integer N. Constraints:
T is in the range of [0, 10000]
N is in the range of [0, 8000000]
Output
For each case output the answer modulo 1000000007 in a single line.
Sample Input
5
0
1
2
3
4
Sample Output
0
1
4
15
64
题意:给n个不同的数,求子集的排列数
分析:做道题竟然没想到是递推,天真的是考求组合数的知识。之后在看到大神讲解焕然大悟
以n为例:当子集是1个数时,有n种情况,子集个数是2,就有n*(n-1),子集个数为三,就有n*(n-1)*(n*2)....直到为n时就是 n*(n-1)*(n-2)....1;其实也是在排列组合数
把s[n] = n + n*(n-1) + n*(n-1)*(n-2) + .....+n*(n-1)*(n-2)...*1;把n提出来就是s[n] = n*( 1+(n-1)+(n-1)*(n-2) +...... +(n-2)*...*1) = n*(1+s[n-1])
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int mod = 1e9 + ;
const int MAX = + ;
long long a[MAX];
int main()
{
a[] = ;
a[] = ;
for(int i = ; i <= MAX; i++)
{
a[i] = i * ( a[i - ] + ) % mod;
}
int t;
scanf("%d", &t);
while(t--)
{
int num;
scanf("%d", &num);
printf("%lld\n", a[num]);
}
return ;
}