#P13255. [GCJ 2014 #1C] Enclosure

    ID: 15121 远端评测题 3000~10000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP贪心2014Google Code Jam

[GCJ 2014 #1C] Enclosure

题目描述

Your task in this problem is to find out the minimum number of stones needed to place on an NN-by-MM rectangular grid (NN horizontal line segments and MM vertical line segments) to enclose at least KK intersection points. An intersection point is enclosed if either of the following conditions is true:

  1. A stone is placed at the point.
  2. Starting from the point, we cannot trace a path along grid lines to reach an empty point on the grid border through empty intersection points only.

For example, to enclose 88 points on a 4×54\times 5 grid, we need at least 66 stones. One of many valid stone layouts is shown below. Enclosed points are marked with an "x".

输入格式

The first line of the input gives the number of test cases, TT. TT lines follow. Each test case is a line of three integers: NN MM KK.

输出格式

For each test case, output one line containing "Case #xx: yy", where xx is the test case number (starting from 1) and yy is the minimum number of stones needed.

2
4 5 8
3 5 11
Case #1: 6
Case #2: 8

提示

Sample Explanation

  • 1T1001 \leq T \leq 100.
  • 1N1 \leq N.
  • 1M1 \leq M.
  • 1KN×M1 \leq K \leq N \times M.

Small dataset(15 Pts)

  • Time limit: 60 3 seconds.
  • N×M20N \times M \leq 20.

Large dataset(30 Pts)

  • Time limit: 120 10 seconds.
  • N×M1000N \times M \leq 1000.