EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. Meta Coding Competitions
  2. 2011
  3. Round 1A

Diversity Number

https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1a/problems/A

Question

Let's call a sequence of integers a1,a2,...,aNa_1,a_2,...,a_Na1​,a2​,...,aN​ almost monotonic if first K elements are non-decreasing sequence and last N−K+1N-K+1N−K+1 elements are non-increasing sequence: a1≤a2≤...≤aKa_1\le a_2≤...≤a_Ka1​≤a2​≤...≤aK​ and aK≥aK+1≥...≥aNa_K≥a_{K+1}≥...≥a_NaK​≥aK+1​≥...≥aN​.

The diversity number of a sequence a1,a2,...,aNa_1,a_2,...,a_Na1​,a2​,...,aN​ is the number of possible sequences b1,b2,...,bNb_1,b_2,...,b_Nb1​,b2​,...,bN​ for which 0≤bi<ai0≤b_i<a_i0≤bi​<ai​ and all of the numbers b1,b2,...,bNb_1,b_2,...,b_Nb1​,b2​,...,bN​ are different. The diversity number of an empty sequence is 1.

You need to find the sum of the diversity numbers of all almost monotonic subsequences of a sequence. Since this number can be very large, find it modulo 109+710^9+7109+7. A subsequence is a sequence that can be obtained from another sequence by deleting some elements without changing the order of the remaining elements. Two sequences are considered different if their lengths differ or there is at least one position at which they differ.

Input Format

The first line of the input file consists of a single number T, the number of test cases. Each test case consists of a number M, the number of elements in a sequence, followed by M numbers n, elements of some sequence (note that this sequence is not necessarily almost monotonic). All tokens are whitespace-separated.

Constraints

T=20T = 20T=20
1≤M,n≤1001 \le M, n \le 1001≤M,n≤100

Output Format

Output T lines, with the answer to each test case on a single line.

Sample Inputs:

Input

5
1
1
2
2 1
3
1 3 2
4
1 3 1 2
4
2 3 4 3

Output

2
5
15
17
80

Solution

PreviousRound 1ANextTurn on the Lights

Last updated 2 months ago