码迷,mamicode.com
首页 > 其他好文 > 详细

SCU 4424(求子集排列数)

时间:2015-12-24 00:33:44      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

A - A
Time Limit:0MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

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

 

 

SCU 4424(求子集排列数)

标签:

原文地址:http://www.cnblogs.com/zhaopAC/p/5071621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!