蓝桥杯练习题:格子分割问题.pdfVIP

  • 0
  • 0
  • 约1.91千字
  • 约 4页
  • 2026-02-05 发布于北京
  • 举报

问题描述

如下图所示,3x3的格子中填写了一些整数。

+--*--+--+

|10*1|52|

+--****--+

|20|30*1|

*******--+

|1|2|3|

+--+--+--+

我们沿着图中的星号线剪开,得到两个部分,每个部分的数字和都是60。

本题的要求就是请你编程判定:对给定的mxn的格子中的整数,是否可以分割为两

个部分,使得这两个区域的数字和相等。

如果存在多种解答,请输出包含左上角格子的那个区域包含的格子的最小数目。

如果无法分割,则输出0。

输入格式

程序先读入两个整数mn用空格分割(m,n10)。

表示表格的宽度和高度。

接下来是n行,每行m个正整数,用空格分开。每个整数不大于10000。

输出格式

输出一个整数,表示在所有解中,包含左上角的分割区可能包含的最小的格子数目。

样例输入1

33

样例输出1

3

样例输入2

43

1111

130802

111100

样例输出2

10

问题描述

Asshowninthefigurebelow,someintegersarefilledina3x3

grid.

+--*--+--+|10*

1|52|+--****--+

|20|30*1|

*******--+

|1|2|3|+--+--

--

++

Wecutalongthestarlinesinthefiguretogettwoparts,eachwithasumofnumbersequalto60.

Therequirementofthisproblemistodeterminethroughprogramming:whethertheintegersinthegivenmxn

gridcanbedividedintotwopartssuchthatthesumsofthenumbersinthesetworegionsareequal.

Iftherearemultiplesolutions,outputtheminimumnumberofcellsintheregionthatincludesthetop-left

cell.

Ifitcannotbedivided,output0.

输格式

Theprogramfirstreadstwointegersmandnseparatedbyaspace(mn).These,

10

representthewidthandheightofthetable.Next,therearenlines,eachcontainingm

positiveintegersseparaedbyspaces.Eachintegerdotesnotexceed10000.

输格式

Outputasingleintegerrepresentingtheminimumnumberofcellsthatcanbecontainedinthepartitionincluding

thetop-leftcorner,amongallpossiblesolutions.

SampleInput

1

3310152

2030112

3

Sample

Output1

3

SampleInput

2

431111130

802111100

Sample

Output2

10

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档