Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int ncr[51][51]={-1};
int per(int l, int r) {
if (l==1) {
return r;
}
else if (l==r) {
return 1;
}
else if (ncr[l][r]!=-1) {
return ncr[l][r];
}
else {
return ncr[l][r]=per(l-1,r-1)+per(l,r-1);
}
}
signed main() {
int t;
cin >> t;
while (t--) {
int n,m;
cin>>n>>m;
vector <int> a(n);
for (int i = 0;i<n;i++)
cin >> a[i];
sort(a.begin(),a.end());
int cnt1 = 0,cnt2 = 0;
cnt2 = count(a.begin(),a.end(),a[m-1]);
for (int i = 0;i<51;i++) {
for (int j = 0;j<51;j++) {
ncr[i][j]=-1;
}
}
for (int i = m-1;i>=0;i--) {
if (a[m-1]!=a[i]) {
break;
}
else {
cnt1++;
}
}
int ans = per(cnt1,cnt2);
cout << ans << endl;
}
}
from math import factorial
i = int(input())
for _ in range(i):
a,b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
p=c[b-1]
f=c.count(p)
e=c[:b].count(p)
print(factorial(f)//(factorial(e)*factorial(f-e)))
#include <stdio.h>
#include <stdlib.h>
long long c[55][55];
int cmp (const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main ()
{
int t, n, k, cnt, slot;
int data[50];
c[0][0] = 1;
for (int i = 1; i <= 50; i++)
{
c[i][0] = 1;
for (int j = 1; j <= i; j++)
{
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
scanf("%d", &t);
while (t--)
{
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
{
scanf("%d", &data[i]);
}
qsort(data, n, sizeof(int), cmp);
slot=0;
cnt=0;
for (int i = 0; i < n; i++)
{
if (data[i] == data[k-1])
{
cnt++;
}
}
for (int i = 0; i < k; i++)
{
if (data[i] == data[k-1])
{
slot++;
}
}
printf("%lld\n", c[cnt][slot]);
}
return 0;
}
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<Long> answer = new ArrayList<Long>();
while (t-- > 0) {
int n = sc.nextInt();
int k = sc.nextInt();
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
list.add(sc.nextInt());
}
Collections.sort(list);
int countOfMaxelem = 0, countInSubStr = 0;
int maxElem = list.get(k - 1);
for (int i = 0; i < n; i++) {
if (list.get(i) == maxElem) {
if(i < k) countInSubStr++;
countOfMaxelem++;
}else if(list.get(i) > maxElem){
break;
}
}
answer.add(nCr(countOfMaxelem, countInSubStr));
}
answer.forEach(System.out::println);
}
static long nCr(int n, int r) {
long result = 1;
for (int i = 0; i < r; i++) {
result = result * (n - i) / (i + 1);
}
return result;
}
}
def integer_list():
return list(map(int, input().split()))
def string_list():
return list(map(str, input().split()))
def hetro_list():
return list(input().split())
import math
import sys
from collections import Counter
fact = [0]*51
fact[0] = 1
for i in range(1, 51):
fact[i] = (fact[i - 1] * i)
def main():
lst.sort()
seq = lst[:k]
dct2 = Counter(seq)
dct = Counter(lst)
ans = 1
for ele in dct2:
ele_req = dct2[ele]
ele_av = dct[ele]
ans *= fact[ele_av]//(fact[ele_req]*fact[ele_av - ele_req])
print(ans)
t = int(input())
for _ in range(t):
n, k = integer_list()
lst = integer_list()
main()
def nCr(n,r):
v = 1
if r > n:
v = 0
else:
k = n-r
if k < r: # make k larger
r,k = k,r
# endif
while n > k:
v = v*n
n -= 1
# endwhile
while r > 1:
v = v/r
r -= 1
# endwhile
# endif
return v
# end fun
t = int(raw_input())
for i in xrange(t):
st = raw_input().split()
N = int(st[0])
K = int(st[1])
L = []
st = raw_input().split()
for k in st:
L.append(int(k))
# endfor k
L.sort()
v = L[-1]
L.append(v+1)
v = L[K-1]
cnt= 0
p = K
while L[p] == v:
cnt += 1
p += 1
# endwhile
a = 0
for p in range(K):
if L[p] == v:
a += 1
# endif
# endfor p
cnt += a
r = nCr(cnt,a)
print r
# endfor i
using System;
using System.Linq;
using System.Numerics;
public class Test
{
public static void Main()
{
var line = Console.ReadLine();
if (string.IsNullOrWhiteSpace(line))
return;
int testCases = 0;
if (!int.TryParse(line, out testCases))
return;
for(int i = 0; i < testCases; i++)
{
var paramaters = Array.ConvertAll(Console.ReadLine().Split(' '), e => int.Parse(e));
var sequence = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).OrderBy(e => e).ToList();
int K = paramaters[1];
var sub_seq = sequence.Take(K).ToArray();
int max = sub_seq.Last();
int cnt = sequence.Where(s => s == max).Count();
int Y = sub_seq.Where(s => s == max).Count();
BigInteger result = Factorial(cnt) / (Factorial(Y) * Factorial(cnt - Y));
Console.WriteLine(result);
}
}
public static BigInteger Factorial(int n)
{
if (n == 1 || n == 0)
return new BigInteger(1);
return n * Factorial(n - 1);
}
}
package main
import (
"bufio"
"bytes"
"fmt"
"os"
"sort"
)
func main() {
reader := bufio.NewReader(os.Stdin)
tc := readNum(reader)
var buf bytes.Buffer
for tc > 0 {
tc--
n, k := readTwoNums(reader)
A := readNNums(reader, n)
res := solve(A, k)
buf.WriteString(fmt.Sprintf("%d\n", res))
}
fmt.Print(buf.String())
}
func readUint64(bytes []byte, from int, val *uint64) int {
i := from
var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp
return i
}
func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}
func readString(reader *bufio.Reader) string {
s, _ := reader.ReadString('\n')
for i := 0; i < len(s); i++ {
if s[i] == '\n' || s[i] == '\r' {
return s[:i]
}
}
return s
}
func readNum(reader *bufio.Reader) (a int) {
bs, _ := reader.ReadBytes('\n')
readInt(bs, 0, &a)
return
}
func readTwoNums(reader *bufio.Reader) (a int, b int) {
res := readNNums(reader, 2)
a, b = res[0], res[1]
return
}
func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
res := readNNums(reader, 3)
a, b, c = res[0], res[1], res[2]
return
}
func readNNums(reader *bufio.Reader, n int) []int {
res := make([]int, n)
x := 0
bs, _ := reader.ReadBytes('\n')
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
x = readInt(bs, x, &res[i])
}
return res
}
const N = 51
var C [N][N]int64
func init() {
C[0][0] = 1
for i := 1; i < N; i++ {
C[i][0] = 1
for j := 1; j <= i; j++ {
C[i][j] = C[i-1][j-1] + C[i-1][j]
}
}
}
func solve(A []int, k int) int64 {
n := len(A)
sort.Ints(A)
// sum must be the first k elements
x := A[k-1]
var i int
for i < n && A[i] < x {
i++
}
// A[i] == x
j := i
for j < n && A[j] == x {
j++
}
// A[j] > x
a := j - i
b := k - i
return C[a][b]
}
In our experience, we suggest you solve this Chef and Interesting Subsequences CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Chef and Interesting Subsequences CodeChef Solution.
I hope this Chef and Interesting Subsequences CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!