• 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
    
    
    
     
  • 相关阅读:
    http和https
    openstack
    openstack安全问题
    openstack优势
    java多线程实现方式
    python多进程实现的几种方式
    Java 在提取url 生成图片以及正则表达式
    idea 生成 可执行文件
    dw cs6 支持高分辨率
    svchost.exe 大量占用的问题
  • 原文地址:https://www.cnblogs.com/zhaopAC/p/5071621.html
Copyright © 2020-2023  润新知