fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int cmp(const void *a, const void *b) {
  7. return(*(int*)b - *(int*)a);
  8. }
  9.  
  10. unsigned int fact(unsigned int a) {
  11. return (a==1 || a==0) ? 1 : fact(a-1)*a;
  12. }
  13.  
  14. int main() {
  15. int t, p[11], k, tot, act, pas, el, r;
  16. scanf("%d", &t);
  17. while(t--) {
  18. act=0; pas=0; tot=0; el=0;
  19. for(int i=0; i<11; i++) scanf("%d", &p[i]);
  20. scanf("%d", &k);
  21. qsort(p, 11, sizeof(int), cmp);
  22. el=p[10-k];
  23. for(int i=10; i>k-1; i--) if(el==p[i]) act++;
  24. for(int i=k-1; i>0; i--) if(el==p[i]) pas++;
  25. tot=act+pas; r=0; r=fact(tot)/(fact(act)*fact(tot-act));
  26. printf("%d\n", r);
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3344KB
stdin
5
1 2 3 4 5 6 7 8 9 10 11
3
2 5 1 2 4 1 6 5 2 2 1
6
1 1 1 1 1 1 1 1 1 1 1
11
84 82 84 81 59 62 69 44 2 6 23
3
75 78 42 29 76 88 32 53 82 13 27
2
stdout
1
6
1
1
1