fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. // freopen("rooks.in","r",stdin);
  28. int T;
  29. scanf(" %d",&T);
  30.  
  31. for(int t =0; t < T; t++) {
  32. int N,M,K,a,b;
  33. scanf(" %d %d %d",&N,&M,&K);
  34. set<int> X,Y;
  35. for(int i =0; i < K; i++) {
  36. scanf(" %d %d",&a,&b);
  37. X.insert(a);
  38. Y.insert(b);}
  39.  
  40. int A =X.size(), B =Y.size();
  41. if(A < B) {
  42. swap(N,M);
  43. swap(A,B);}
  44. long long mod =1000000007;
  45. vector< vector<long long> > C(A+1,vector<long long>(B+1,0));
  46. C[0][B] =1;
  47. for(int i =1; i <= A; i++) for(int j =0; j <= B; j++) {
  48. if(j < B) C[i][j] =(C[i-1][j]*(M-j)+C[i-1][j+1]*(j+1))%mod;
  49. else C[i][j] =(C[i-1][j]*(M-B))%mod;
  50. if(C[i][j] < 0) C[i][j] +=mod;}
  51.  
  52. printf("Case %d: %d %lld\n",t+1,A,C[A][0]);}
  53. return 0;}
  54.  
  55. // look at my code
  56. // my code is amazing
Success #stdin #stdout 0s 3480KB
stdin
2
4 5 2
1 2
1 3
3 4 3
1 1
2 2
3 3
stdout
Case 1: 2 7
Case 2: 3 6