F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tom and permutation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 719    Accepted Submission(s): 338


Problem Description
Tom has learned how to calculate the number of inversions in a permutation of n distinct objects by coding, his teacher gives him a problem:
Give you a permutation of n distinct integer from 1 to n, there are many permutations of 1-n is smaller than the given permutation on dictionary order, and for each of them, you can calculate the number of inversions by coding. You need to find out sum total of them.
Tom doesn't know how to do, he wants you to help him.
Because the number may be very large, output the answer to the problem modulo ${10}^{9}+7$.
 

Input
Multi test cases(about 20). For each case, the first line contains a positive integer n, the second line contains n integers, it's a permutation of 1-n.
$n\leq 100$
 

Output
For each case, print one line, the answer to the problem modulo ${10}^{9}+7$.
 

Sample Input
3 2 1 3 5 2 1 4 3 5
 

Sample Output
1 75
 

Hint
The input may be very big, we might as well optimize input.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 19:47:58, Gzip enabled