1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// @Title: 射箭比赛中的最大得分 (Maximum Points in an Archery Competition)
// @Author: 15816537946@163.com
// @Date: 2022-03-20 13:08:18
// @Runtime: 48 ms
// @Memory: 9.5 MB
class Solution {
public:
    vector<int> maximumBobPoints(int numArrows, vector<int>& aliceArrows) {
        int n = aliceArrows.size();
        int ans = 0;
        vector<int> best(n);
        for (int i = 0; i < (1 << n); i++) {
            int tot = 0, score = 0;
            for (int j = 0; j < n; j++) if (i >> j & 1) tot += aliceArrows[j] + 1, score += j;
            if (tot <= numArrows && score > ans) {
                ans = score;
                for (int j = 0; j < n; j++)
                    if (i >> j & 1) best[j] = aliceArrows[j] + 1;
                    else best[j] = 0;
                best[n - 1] += numArrows - tot;
            }
        }
        return best;
    }
};