private void search(List<Integer> nums, List<Integer> counts,
                int index, int target, ArrayDeque<Integer> s,
                ArrayList<ArrayList<Integer>> ans) {
            if (target == 0) {
                ans.add(new ArrayList<Integer>(s));
            }
            if (target <= 0 || index == nums.size()) {
                return;
            }
            int n = nums.get(index);
            int count = counts.get(index);
            for (int i = 0; i <= count; i++) {
                search(nums, counts, index + 1, target - i * n, s, ans);
                s.offerLast(n);
            }
            for (int i = 0; i <= count; i++) {
                s.removeLast();
            }
        }