It logically doesn't make any sense to place any guards on the ends, since it's more effective to put them one off the ends.
IE, with your ABCD scenario, you don't ever need to put any guards on A or D... since a guard on B is more effective than a guard on A, and a guard on C is more effective than a guard on D.
So really, this problem is very simple.
- Start with position B and place as many guards to satisfy A
- Then move to position C and place as many to satisfy position B
- and so on until you get to the 2nd to last element -- where you would add guards to satisfy all 3 of the last elements.
In your case, we'd start with this:
A = 0 guards, 100 unguarded
B = 0 guards, 200 unguarded
C = 0 guards, 100 unguarded
D = 0 guards, 100 unguarded
|
guards can guard 100 each
Step 1: put enough guards on B to satisfy A:
A = 0 guards, 0 unguarded
B = 1 guard , 200 unguarded
C = 0 guards, 100 unguarded
D = 0 guards, 100 unguarded
|
Step 2: Place enough on C to satisfy B:
A = 0 guards, 0 unguarded
B = 1 guard , 0 unguarded
C = 2 guards, 100 unguarded
D = 0 guards, 100 unguarded
|
Step 3: Place enough on the 2nd to last element (C) to satisfy the last elements:
A = 0 guards, 0 unguarded
B = 1 guard , 0 unguarded
C = 4 guards, 0 unguarded
D = 0 guards, 0 unguarded
|
EDIT:
It works with more complex setups also:
Each guard can guard $10
A = 0, $65
B = 0, $42
C = 0, $116
D = 0, $8
E = 0, $51
|
Fill B to guard A:
A = 0, $0 (-$65)
B = 7, $37 (+7 guards, -$5)
C = 0, $116
D = 0, $8
E = 0, $51
|
Fill C to guard B:
A = 0, $0
B = 7, $0 (-$37)
C = 4, $113 (+4, -$3)
D = 0, $8
E = 0, $51
|
Fill D to guard C:
A = 0, $0
B = 7, $0
C = 4, $0 (-$113)
D = 12, $1 (+12, -$7)
E = 0, $51
|
Add more to D to guard D&E:
A = 0, $0
B = 7, $0
C = 4, $0
D = 18, $0 (+6, -$1)
E = 0, $0 (-$51)
(8 guard units wasted)
|