天天看点

codechef Top Batsmen题解

a cricket team consists of 11 players and some are good at batting, others are good at bowling and some of them are good at both batting and bowling. the batting coach wants to select exactly k players having maximum possible sum of scores.

given the batting score of each of the 11 players, find the number of ways in which we can select exactly k players such that the sum of their scores is the maximum possible. two ways are different if there is a player who is selected in one

of them is not in the other. see explanation of sample cases for more clarity.

first line contains t, number of test cases ( 1 ≤ t ≤ 100 ). t cases follow, each having 2 lines. first line of each case contains scores of 11 players ( 1 ≤ score ≤ 100 ) and the second line contains k (1 ≤ k ≤ 11)

for each test case, output the answer in a new line.

一个简单的组合问题。

这里主要熟悉priority_queue的用法:

1 它没有clear用法,需要手动清空,别忘记循环中清零了,我老是犯这个错误

2 使用这些容器要注意判空,否则范围溢出,也是老毛病了

当然,其实本题有更加简洁的写法。

继续阅读