SCU oj 4424 Permutations(递推)

题目链接

4424: Permutations

Submit your solution     Discuss this problem     Best solutions

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

Author

baihacker

题解容易得出递推公式:f ( n ) = ( 1 + f( n-1 ) ) * n ;

代码如下:

#include<cstdio>
#include<cstring>
#include<set>
#include<iostream>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<cctype>
#include<algorithm>
#define inff 0x3fffffff
#define nn 8100000
#define mod 1000000007
typedef long long LL;
using namespace std;
LL ans[nn];
int main()
{
    int i;
    ans[0]=0;
    for(i=1;i<=8000000;i++)
    {
        ans[i]=((ans[i-1]+1)*i)%mod;
    }
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%lld\n",ans[n]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值