1371-energetic Pandas

Source: Internet
Author: User

1371-energetic Pandas
PDF (中文版) Statistics Forum
Time Limit:2 second (s) Memory limit:32 MB

There is n bamboos of different weights Wi. There is n pandas of different capacity CAPi. How many ways the pandas can carry the bamboos so then each panda carries exactly one bamboo, every bamboo was carried by O NE Panda and a panda cannot carry a bamboo that's heavier than its capacity. The ways would be considered different if at least one panda carries a different bamboo.

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case starts with a line containing an integer n (1≤n≤1000) denoting the number of pandas and bamboos. The next line contains n space separated distinct integers denoting the weights of being bamboos. The next line contains n space separated distinct integers denoting the capacities for the pandas. the weights and the capacities lie in the range [1, 109].

Output

For each case, print the case number and the number of ways those pandas can carry the bamboos. This number can be very big. So print the result modulo 007.

Sample Input Output for Sample Input

3

5

1 2 3) 4 5

1 2 3) 4 5

2

1 3

2 2

3

2 3 4

6 3 5

Case 1:1

Case 2:0

Case 3:4

Problem setter:f.a. Rezaur Rahman chowdhuryspecial thanks:jane Alam Jan idea: Discretization + permutation;
1#include <stdio.h>2#include <algorithm>3#include <iostream>4#include <string.h>5#include <queue>6#include <stack>7 using namespacestd;8typedefLong LongLL;9 intans[10000];Ten intbns[10000]; One intdns[10000]; A intcn[10000]; - intaa[10000]; - intbb[10000]; the Const intn=1e9+7; - intMainvoid) - { -         intk,i,j; +scanf"%d",&k); -         intCA; +         intN; A          for(ca=1; ca<=k; ca++) at         { -scanf"%d",&n); -                 intCnt=0; -Memset (CN,0,sizeof(CN)); -                  for(i=0; i<n; i++) -                 { inscanf"%d",&ans[i]); -dns[cnt++]=Ans[i]; to                 } +                  for(i=0; i<n; i++) -                 { thescanf"%d",&bns[i]); *dns[cnt++]=Bns[i]; $                 }Panax NotoginsengSort (dns,dns+2*n); -                  for(i=0; i<n; i++) the                 { +                         intL=0; A                         intR=2*n-1; the                         intId=0; +                          while(l<=R) -                         { $                                 intMid= (L+R)/2; $                                 if(dns[mid]>=Ans[i]) -                                 { -Id=mid; ther=mid-1; -                                 }Wuyi                                 ElseL=mid+1; the                         } -ans[i]=ID; Wu                 } -Sort (ans,ans+n); About                  for(i=0; i<n; i++) $                 { -                         intL=0; -                         intR=2*n-1; -                         intId=0; A                          while(l<=R) +                         { the                                 intMid= (L+R)/2; -                                 if(bns[i]<=Dns[mid]) $                                 { theId=mid; ther=mid-1; the                                 } the                                 ElseL=mid+1; -                         } inbns[i]=ID; thecn[id]++; the                 } About                 intgg=0; the                  for(i=0; i< the; i++) the                 { the                         if(cn[i]>0) +                         { -aa[gg]=i; thebb[gg++]=Cn[i];Bayi                         } the                 } theLL sum=1; -                 intcc=gg-1; -LL pp=0; the                  for(i=n-1; i>=0; i--) the                 { the  the                          while(aa[cc]>=ans[i]&&cc>=0) -                         { thePp= (pp+BB[CC]); theCC--; the                         }94                         if(pp>0) the                         { thesum= (SUM*PP)%N; thepp-=1;98                         } About                         Else -                         {101sum=0;102                                  Break;103                         }104}printf ("Case %d:", CA); theprintf"%lld\n", sum);106         }107         return 0;108}

1371-energetic Pandas

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.