zoukankan      html  css  js  c++  java
  • AtCoder Regular Contest 077 D

    题目链接:http://arc077.contest.atcoder.jp/tasks/arc077_b

    Time limit : 2sec / Memory limit : 256MB

    Score : 600 points

    Problem Statement

    You are given an integer sequence of length n+1a1,a2,…,an+1, which consists of the n integers 1,…,n. It is known that each of the n integers 1,…,n appears at least once in this sequence.

    For each integer k=1,…,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 109+7.

    Notes

    • If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.

    • A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

    Constraints

    • 1≤n≤105
    • 1≤ain
    • Each of the integers 1,…,n appears in the sequence.
    • n and ai are integers.

    Input

    Input is given from Standard Input in the following format:

    n
    a1 a2 ... an+1
    

    Output

    Print n+1 lines. The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 109+7.


    Sample Input 1

    Copy
    3
    1 2 1 3
    

    Sample Output 1

    Copy
    3
    5
    4
    1
    

    There are three subsequences with length 11 and 2 and 3.

    There are five subsequences with length 21,1 and 1,2 and 1,3 and 2,1 and 2,3.

    There are four subsequences with length 31,1,3 and 1,2,1 and 1,2,3 and 2,1,3.

    There is one subsequence with length 41,2,1,3.


    Sample Input 2

    Copy
    1
    1 1
    

    Sample Output 2

    Copy
    1
    1
    

    There is one subsequence with length 11.

    There is one subsequence with length 21,1.


    Sample Input 3

    Copy
    32
    29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9
    

    Sample Output 3

    Copy
    32
    525
    5453
    40919
    237336
    1107568
    4272048
    13884156
    38567100
    92561040
    193536720
    354817320
    573166440
    818809200
    37158313
    166803103
    166803103
    37158313
    818809200
    573166440
    354817320
    193536720
    92561040
    38567100
    13884156
    4272048
    1107568
    237336
    40920
    5456
    528
    33
    1
    

    Be sure to print the numbers modulo 109+7.

    题目大意:从n+1个序列中选出长度为k的不同子序列的个数 
    解题思路: 
    注意到有两个相同的元素 
    当子序列不含有相同的元素中间的元素时,子序列会被多算一次,其他情况确定,所以最终结果为: 
    (C(n+1,k)-C(n-d,k-1))%MOD

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 #include <stack>
    14 using namespace std;
    15 #define lowbit(x) (x&(-x))
    16 #define max(x,y) (x>y?x:y)
    17 #define min(x,y) (x<y?x:y)
    18 #define MAX 100000000000000000
    19 #define MOD 1000000007
    20 #define pi acos(-1.0)
    21 #define ei exp(1
    22 #define PI 3.141592653589793238462
    23 #define INF 0x3f3f3f3f3f
    24 #define mem(a) (memset(a,0,sizeof(a)))
    25 typedef long long ll;
    26 ll gcd(ll a,ll b){
    27     return b?gcd(b,a%b):a;
    28 }
    29 const int N=200005;
    30 const int maxn = 1e5 + 10;
    31 ll pos[maxn],fac[maxn],facm[maxn];
    32 ll quick_pow(ll a,ll n,ll p)
    33 {
    34     ll x = a;
    35     ll res = 1;
    36     while(n){
    37         if(n & 1){
    38             res = ((ll)res * (ll)x) % p;
    39         }
    40         n >>= 1;
    41         x = ((ll)x*(ll)x) % p;
    42     }
    43     return res;
    44 }
    45 ll C(ll n,ll k){
    46     if(k > n) return 0ll;
    47     ll ans = fac[k]*fac[n-k]%MOD;
    48     ans = (fac[n]*quick_pow(ans,MOD-2ll,MOD))%MOD;
    49     return ans;
    50 }
    51 int main()
    52 {
    53     fac[0] = 1;
    54     for(int i = 1;i < maxn;i++)
    55         fac[i] = (fac[i-1]*i)%MOD;
    56     ll n;
    57     scanf("%lld", &n);
    58     n++;
    59     ll m, x;
    60     for(int i = 1;i <= n;i++){
    61         scanf("%lld", &x);
    62         if (pos[x]){
    63             m = n - (i - pos[x] + 1);
    64             break;
    65         }
    66         pos[x] = i;
    67     }
    68     for(int i = 1;i <= n;i++)
    69         printf("%lld
    ", (C(n, i) - C(m, i-1)+MOD) % MOD);
    70     return 0;
    71 }
  • 相关阅读:
    linux cfs调度器
    运算符重载
    linux cfs调度器_模型实现
    linux cfs调度器_理论模型
    jiffies存放
    在C++中实现不可继承的类
    装饰模式(Decorator Pattern)--------结构型模式
    How to use base class's assignment operator in C++
    组合模式(Composite Pattern) ------------结构型模式
    what's the help of "unnecessary" pointer comparison
  • 原文地址:https://www.cnblogs.com/shixinzei/p/7290537.html
Copyright © 2011-2022 走看看