用户输出
1 1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#557 | #999. 蛋蛋 | Accepted | 100 | 201 ms | 2912 K | Python 3 / 769 B | s230034010 | 2023-10-15 14:55:04 |
n = int(input())
needs = list(map(int, input().split()))
m = int(input())
foods = [list(map(int, input().split())) for _ in range(m)]
ans = m + 1
selected_foods = []
def backtrack(curr, selected, remains):
global ans, selected_foods
if len(selected) > ans:
return
if all(remain <= 0 for remain in remains):
if len(selected) < ans:
ans = len(selected)
selected_foods = selected[:]
return
if curr == m:
return
new_remains = [remains[i] - foods[curr][i] for i in range(n)]
backtrack(curr+1, selected + [curr], new_remains)
backtrack(curr+1, selected, remains)
backtrack(0, [], needs)
print(ans, *sorted([i+1 for i in selected_foods]))
用户输出
1 3
系统信息
Exited with return code 0
用户输出
2 2 3
系统信息
Exited with return code 0
用户输出
5 1 2 3 4 5
系统信息
Exited with return code 0
8
10 10 10 10 10 10 10 10
7
1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
1
<62 bytes omitted>
用户输出
2 6 7
系统信息
Exited with return code 0