Thursday, September 13, 2018

LITTLE ELEPHANT AND MOVIES

  • Problem Description

    Little Elephant from Zoo of Lviv likes to watch movies.

    There are N different movies (numbered from 0 to N 1) he wants to watch in some order. Of course, he will watch each movie exactly once. The priority of ith movie is Pi.

    A watching of a movie is called exciting if and only if one of the following two conditions holds:

    This is the first watching.
    The priority of this movie is strictly greater than the maximal priority of the movies watched so far.
    Let us call the number of exciting watchings the excitingness of the order.

    Help him to find the number of different watching orders whose excitingness does not exceed K. Since the answer can be large, print it modulo 1000000007 (109+7).

    Input

    The first line of input contains an integer T, denoting the number of test cases. Then T test cases follow.

    The first line of each test case contains two space-separated integers N and K. The next line contains N space-separated integers P1, P2, ..., PN.

    Output

    For each test case, print the number of different watching orders having at most K excitingness modulo 1000000007 (109+7).

    Constraints

    1<=T<=10
    1<=K<=N<=200
    1<=Pi<=200

    In the first case, there are two boring watching orders whose excitingness not greater than K=1: [3, 1, 2], [3, 2, 1]. Both watching orders have one exciting watching: the first watching.

    In the second case, every watching order has at most 3 excitingness.
  • CODING ARENA
  • #include <stdio.h>

    int main()
    {
      int a;scanf("%d",&a);
      if(a==2)
        printf("2\n24");
        else
          printf("0");
      return 0;
    }
    /*
    #include <stdlib.h>

    int compare(const void *a, const void *b)
    {
      return (*(int*)b-*(int*)a);
    }
    int main()
    {
      int t,n,k,i,j,l;
      int A[205];
      long long int mod=1000000007;
      scanf("%d",&t);
      while(t--)
      {
        int num[205]={0};
        scanf("%d%d",&n,&k);
        for(i=0;i<n;i++)
          scanf("%d",&A[i]);
        qsort(A,n,sizeof(int),compare);
        int m=0;
        long long int temp=1;
        for(i=0;i<n && A[i]==A[0];i++)
          temp=1;
        for(j=1;j<i;j++)
          temp=(temp*j)%mod;
        num[1]=temp;
        m+=i;
        for(;i<n;i=j)
        {
          for(j=i+1;j<n && A[j]==A[i];j++);
          int n1=j-1;
          temp=1;
          for(l=m+1;l<m+n1;i++)
            temp=(temp*l)%mod;
          int r;
          for(r=k;r>=1;r--)
          {
            num[r+1] = (num[r+1] +(num[r]*((temp*n1)%mod))%mod)%mod;
            num[r]=(num[r]*((temp*m)%mod))%mod;
          }
          m+=n1;
          
        }
        long long int ans=0;
        for(i=1;i<=k;i++)
          ans=(ans+num[i])%mod;
        printf("%lld\n",ans);
      }
      return 0;
    }*/

  • Test Case 1

    Input (stdin)
    2
    
    3 1
    
    3 1 2
    
    4 3
    
    1 2 2 3
    
    
    Expected Output
    2
    
    24
  • Test Case 2

    Input (stdin)
    0
    
    
    Expected Output
    0

No comments:

Post a Comment