Elite Forces

0

0 votes
Problem

Let's tell you the legendary story of two famous kings William and Harold . Both were sworn enemies of each other & William want to conquer the Harold's city . But first William has to defeat Harold's army.

Harold has an army not a huge one but a tactical one. He has got teams in his army in the form of rectangular blocks, such that if any of them are left, William will lose the battle.

Each soldier has a rank in the army, and only a specified rectangular arrangement of them forms a tactical team. If any one of the soldiers in the team dies all the soldiers of that team die. You need to find them and kill them all .But William has limited resources and need to do this in minimum number of ammunition.

You need to find the number of missiles required to defeat Harold and kill all the tactical groups. One missile will kill only one soldiers .

As we all know tactical team are costly so numbers of tactical team in Harold's army will be always less then equal to 100.

Input Format

2 Integers N and M denoting the dimensions of the army
Next N lines contains M integers each denoting the rank of the soldier
single integer Q denoting number of queries
each query consists
PN PM : Two Integer denoting the size of group
Next PN lines contain PM integers denoting the arrangement of the soldiers to form the tactical group

Output Format

print the minimum number of missiles to destroy all the tactical groups

Constraints:

1 <= N, M, PN, PM <= 1000
1<= Q <= 10
1<=rank<=9

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?