Under construction

Still being built. Things may change

Enclosure

Time limit5sMemory limit512 MB

Summary
Place the fewest stones on an N by M grid of at most 20 cells so at least K points are cut off from the border.
Level

Medium4 of 10

Topics
Brute force, BFS, Bit manipulation
Solved
No attempts yet

Problem

A grid is made of NN horizontal lines and MM vertical lines. The horizontal and vertical lines meet at N×MN \times M intersection points, and each intersection point holds at most one stone.

An intersection point is enclosed if either of the following holds.

  1. A stone is placed on the point.
  2. Starting from the point and moving along grid lines, you cannot reach an empty intersection point on the border of the grid by passing through empty intersection points only.

Each move goes along a grid line to a neighbouring intersection point. A path is usable only if its starting point, every point it passes, and its final point are all empty. An empty point on the border is therefore never enclosed.

Place stones so that at least KK points are enclosed. Find the minimum number of stones needed.

For example, enclosing 8 points on a 4×54 \times 5 grid needs at least 6 stones. The picture below shows one such layout, with the enclosed points marked x.

Input

The first line contains the number of test cases, TT. Each of the next TT lines contains three integers NN, MM and KK, separated by spaces.

Limits

  • 1≤T≤1001 \le T \le 100
  • 1≤N1 \le N
  • 1≤M1 \le M
  • 1≤K≤N×M1 \le K \le N \times M
  • N×M≤20N \times M \le 20

Output

For each test case, print one line of the form Case #x: y, where xx is the test case number starting from 1 and yy is the minimum number of stones needed.

Examples5

  1. Example 1

    Input
    2
    4 5 8
    3 5 11
    
    Expected output
    Case #1: 6
    Case #2: 8
    
  2. Example 2

    Input
    1
    1 1 1
    
    Expected output
    Case #1: 1
    
  3. Example 3

    Input
    6
    1 20 1
    1 20 20
    20 1 13
    1 2 2
    2 1 1
    1 7 4
    
    Expected output
    Case #1: 1
    Case #2: 20
    Case #3: 13
    Case #4: 2
    Case #5: 1
    Case #6: 4
    
  4. Example 4

    Input
    9
    3 3 1
    3 3 2
    3 3 3
    3 3 4
    3 3 5
    3 3 6
    3 3 7
    3 3 8
    3 3 9
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 3
    Case #4: 4
    Case #5: 4
    Case #6: 5
    Case #7: 6
    Case #8: 7
    Case #9: 8
    
  5. Example 5

    Input
    20
    4 5 1
    4 5 2
    4 5 3
    4 5 4
    4 5 5
    4 5 6
    4 5 7
    4 5 8
    4 5 9
    4 5 10
    4 5 11
    4 5 12
    4 5 13
    4 5 14
    4 5 15
    4 5 16
    4 5 17
    4 5 18
    4 5 19
    4 5 20
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 3
    Case #4: 4
    Case #5: 4
    Case #6: 5
    Case #7: 6
    Case #8: 6
    Case #9: 7
    Case #10: 7
    Case #11: 8
    Case #12: 8
    Case #13: 9
    Case #14: 9
    Case #15: 10
    Case #16: 10
    Case #17: 11
    Case #18: 12
    Case #19: 13
    Case #20: 14