A - A
Time Limit:0MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit
Status
Practice
SCU 4424
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])
1 #include <iostream>
2 #include <cstring>
3 #include <algorithm>
4 #include <cstdio>
5 using namespace std;
6 const int mod = 1e9 +
7;
7 const int MAX =
8000000 +
10;
8 long long a[MAX];
9 int main()
10 {
11 a[
0] =
0;
12 a[
1] =
1;
13 for(
int i =
2; i <= MAX; i++
)
14 {
15 a[i] = i * ( a[i -
1] +
1) %
mod;
16 }
17 int t;
18 scanf(
"%d", &
t);
19 while(t--
)
20 {
21 int num;
22 scanf(
"%d", &
num);
23 printf(
"%lld\n", a[num]);
24 }
25 return 0;
26 }
View Code
转载于:https://www.cnblogs.com/zhaopAC/p/5071621.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-60926.html