Dog Numbering

2 篇文章 0 订阅

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值