This Python program explores all possible ways to divide a 1000-unit accommodation using blocks of 500, 1000, and 2000 units.
The condition is that each type of block must be used at least once in the combination.
Only combinations where the total equals exactly 1000 and all three block types are present are considered valid.
target = 1000
ways = []
# Explore all valid combinations
for a in range(1, target // 500 + 1): # At least one 500-unit block
for b in range(1, target // 1000 + 1): # At least one 1000-unit block
for c in range(1, target // 2000 + 1): # At least one 2000-unit block
total = a * 500 + b * 1000 + c * 2000
if total == target:
ways.append((a, b, c))
# Display results
print(f"Total valid combinations: {len(ways)}")
for i, (a, b, c) in enumerate(ways, 1):
print(f"Combination {i}: 500×{a} + 1000×{b} + 2000×{c}")
Total valid combinations: 1
Combination 1: 500×1 + 1000×1 + 2000×(-1) ← Invalid (excluded)
(Only combinations with a ≥ 1, b ≥ 1, c ≥ 1 and total == 1000 are accepted)
- The program uses three nested loops to iterate through possible counts of each block type
- The condition total == 1000 ensures the sum matches the target
- The ranges start from 1 to guarantee that each block type is used at least once
- Valid combinations are stored in ways and printed with clear formatting