zoukankan      html  css  js  c++  java
  • UVALive 5971

    Problem J Permutation Counting
    Dexter considers a permutation of first N natural numbers good if it doesn't have x and x+1 appearing consecutively, where (1 ≤ x < N)  For example, for N=3 , all goodpermutations are:
    1. {1, 3, 2}
    2.{2, 1, 3}
    3.{3, 2, 1}
    Input
    Input starts with an integer T (≤ 10000 , denoting the number of test cases.Each
    case starts with a line containing an integer N (1 ≤ N ≤ 106)
    .
    Output
    For each case, print the case number and the number ofgoodpermutations
    modulo1000 000 007
    .
    Sample Input
    Output for Sample Input
    3
    2
    3
    5
    Case 1: 1
    Case 2: 3
    Case 3: 53
     1 #include <map>
     2 #include <set>
     3 #include <list>
     4 #include <cmath>
     5 #include<cctype>
     6 #include <ctime>
     7 #include <deque>
     8 #include <stack>
     9 #include <queue>
    10 #include <cstdio>
    11 #include <string>
    12 #include <vector>
    13 #include<climits>
    14 #include <cstdlib>
    15 #include <cstring>
    16 #include <iostream>
    17 #include <algorithm>
    18 #define LL long long
    19 #define PI 3.1415926535897932626
    20 using namespace std;
    21 int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
    22 #define MAXN 1000005
    23 #define MOD 1000000007
    24 LL ans[MAXN],tmp[MAXN];
    25 void init()
    26 {
    27     ans[1]=1;ans[2]=1;
    28     for (int i=3;i<MAXN;i++)
    29        {
    30            ans[i]=((i-1)*ans[i-1])+(i-2)*ans[i-2];
    31            ans[i]%=MOD;
    32        }
    33 }
    34 int main()
    35 {
    36     init();
    37     int T;int kase=1;
    38     scanf("%d",&T);
    39     while (T--)
    40     {
    41         int N;
    42         scanf("%d",&N);
    43         printf("Case %d: %lld
    ",kase++,ans[N]);
    44     }
    45     return 0;
    46 }
    View Code
     
  • 相关阅读:
    关于粒子发射(CAEmitterLayer)
    自定义cell(xib)中button点击事件不能响应的情况
    xcode意外退出
    iOS开发技巧-2
    禁止UIWebView随键盘的弹起而往上滚动
    内联函数
    使用sudo apt-get出现无法解析域名的问题:“cn.archive.ubuntu.com”
    iOS进阶
    swift 中的defer
    iOS中static的作用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3861467.html
Copyright © 2011-2022 走看看