| Remove maximal number of bricks from the wall such that the top row is unchanged and the wall remains stable | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Complexity (1-100): 30
fig. 1. A wall
fig. 1. The wall after removing bricks Obviously, one can remove a few bricks from a wall so that the wall would remain stable. Fig. 2 shows a possible configuration after removing bricks from the wall on fig. 1. Write a program which, given wall dimensions M and N (0<M,N≤1000), finds a stable wall configuration, ensuing from the solid wall M×N by removing maximal number of bricks such that the top row can remain unchanged. The program should print the number of remaining bricks and the resulting wall configuration. Note: the program is allowed to run no longer than 3 seconds. Self-tests. These are some results:
|
|||||||||||||
| Solution: | solution.pas | ||||||||||||
Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin