# 组合总和 II

<p>给定一个数组&nbsp;<code>candidates</code>&nbsp;和一个目标数&nbsp;<code>target</code>&nbsp;，找出&nbsp;<code>candidates</code>&nbsp;中所有可以使数字和为&nbsp;<code>target</code>&nbsp;的组合。
</p>
<p><code>candidates</code>&nbsp;中的每个数字在每个组合中只能使用一次。</p>
<p><strong>说明：</strong></p>
<ul>
    <li>所有数字（包括目标数）都是正整数。</li>
    <li>解集不能包含重复的组合。&nbsp;</li>
</ul>
<p><strong>示例&nbsp;1:</strong></p>
<pre><strong>输入:</strong> candidates =&nbsp;[10,1,2,7,6,1,5], target =&nbsp;8,<strong><br />所求解集为:</strong>[[1, 7],[1, 2, 5],[2, 6],[1, 1, 6]]</pre>
<p><strong>示例&nbsp;2:</strong></p>
<pre><strong>输入:</strong> candidates =&nbsp;[2,5,2,1,2], target =&nbsp;5,<strong><br />所求解集为:</strong>[[1,2,2],[5]]</pre>

## template

```python
class Solution(object):
	def combinationSum2(self, candidates, target):
		"""
		:type candidates: List[int]
		:type target: int
		:rtype: List[List[int]]
		"""
		candidates.sort()
		dp = [[] for _ in range(target + 1)]
		dp[0].append([])
		for i in range(1, target + 1):
			for j in range(len(candidates)):
				if candidates[j] > i:
					break
				for k in range(len(dp[i - candidates[j]])):
					temp = dp[i - candidates[j]][k][:]
					if len(temp) > 0 and temp[-1] >= j:
						continue
					temp.append(j)
					dp[i].append(temp)
		res = []
		check = {}
		for temp in dp[target]:
			value = [candidates[t] for t in temp]
			try:
				check[str(value)] += 1
			except KeyError:
				check[str(value)] = 1
				res.append(value)
		return res
# %%
s = Solution()
print(s.combinationSum2(candidates = [2,5,2,1,2], target = 5))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```