zoukankan      html  css  js  c++  java
  • SCU 4424(求子集排列数)

    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
    ", a[num]);
    24     }
    25     return 0;
    26 }
    View Code
    
    
    
     
  • 相关阅读:
    服务器状态码
    QuerySet中添加Extra进行SQL查询
    django配置一个网站建设
    MySQL数据库查询中的特殊命令
    125. Valid Palindrome
    121. Best Time to Buy and Sell Stock
    117. Populating Next Right Pointers in Each Node II
    98. Validate Binary Search Tree
    91. Decode Ways
    90. Subsets II
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/5071621.html
Copyright © 2011-2022 走看看