CF598E.Chocolate Bar

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a rectangular chocolate bar consisting of n×mn×m single squares. You want to eat exactly kk squares, so you may need to break the chocolate bar.

In one move you can break any single rectangular piece of chocolate in two rectangular pieces. You can break only by lines between squares: horizontally or vertically. The cost of breaking is equal to square of the break length.

For example, if you have a chocolate bar consisting of 2×32×3 unit squares then you can break it horizontally and get two 1×31×3 pieces (the cost of such breaking is 32=93^{2}=9 ), or you can break it vertically in two ways and get two pieces: 2×12×1 and 2×22×2 (the cost of such breaking is 22=42^{2}=4 ).

For several given values nn , mm and kk find the minimum total cost of breaking. You can eat exactly kk squares of chocolate if after all operations of breaking there is a set of rectangular pieces of chocolate with the total size equal to kk squares. The remaining nmkn·m-k squares are not necessarily form a single rectangular piece.

输入格式

The first line of the input contains a single integer tt ( 1<=t<=409101<=t<=40910 ) — the number of values nn , mm and kk to process.

Each of the next tt lines contains three integers nn , mm and kk ( 1<=n,m<=30,1<=k<=min(nm,50)1<=n,m<=30,1<=k<=min(n·m,50) ) — the dimensions of the chocolate bar and the number of squares you want to eat respectively.

输出格式

For each nn , mm and kk print the minimum total cost needed to break the chocolate bar, in order to make it possible to eat exactly kk squares.

输入输出样例

  • 输入#1

    4
    2 2 1
    2 2 3
    2 2 2
    2 2 4
    

    输出#1

    5
    5
    4
    0
    

说明/提示

In the first query of the sample one needs to perform two breaks:

  • to split 2×22×2 bar into two pieces of 2×12×1 (cost is 22=42^{2}=4 ),
  • to split the resulting 2×12×1 into two 1×11×1 pieces (cost is 12=11^{2}=1 ).

In the second query of the sample one wants to eat 33 unit squares. One can use exactly the same strategy as in the first query of the sample.

首页