B. Dog Numbering
Time Limit: 2.0 Seconds Memory Limit: 65536K
Miss Kim has dogs, and she wants to assign a distinct integer to each dog so she can easily identify them. The dogs have expressed their preferences to Miss Kim. The i-th dog wants an integer between 1 and maxNumber[i], inclusive. Miss Kim must obey the preferences of all their dogs.
Input
The first line will contain the number of test cases. Each case has two lines of input. The first line will contain a integer N (1 ≤ N ≤ 50) indicating the number of dogs. The second line will contain N integers corresponding to maxNumber[i](1 ≤ maxNumber[i] ≤ 1000), separated by spaces.
Output
For each case output a integer in a line, that is the number of ways she can assign numbers to her dogs, modulo 1,000,000,007. If it’s impossible to assign distinct integers to the dogs, output 0.
Sample Input
4
1
5
4
4 4 4 4
2
5 8
3
2 1 2
Sample Output
5
24
35
0
注意:
* 题目中的答案要取膜运算
* 答案超了int型 要用long long
# include<iostream>
# include<queue>
using namespace std;
struct cmp{
bool operator ()(int &a,int &b){
return a>b;//最小值优先
}
};
priority_queue<int,vector<int>,cmp> q;
int main(){
int n;
cin>>n;
while(n--){
while (!q.empty())
q.pop();
int m,temp,k;
long long ans=1;
cin>>m;
k=m;
while(k--){
cin>>temp;
q.push(temp);
}
for(int i=0;i<m;i++){
if(q.top()-i<=0){
ans=0;
break;
}
ans=(ans%1000000007)*(q.top()-i);
q.pop();
}
cout<<ans%1000000007<<endl;
}
return 0;
}