Problem description
As shown, a number of integers are filled in 3 x 3 squares.
+--*--+--+
|10* 1|52|
+--****--+
|20|30* 1|
*******--+
| 1| 2| 3|
+--+--+--+
We cut along the star Line in the diagram and get two parts, each with a number of 60.
The requirement of the subject is to ask you to determine whether the integer in the given m x n lattice can be divided into two parts, making the numbers and the two regions equal.
If there are multiple answers, output the minimum number of squares contained in the area containing the upper-left lattice.
If it cannot be split, the output is 0.
Input format
The program reads in two integer m n with a space partition (M,N<10).
Represents the width and height of a table.
Next is n rows, each m positive integer, separated by a space. Each integer is not greater than 10000.
The output format outputs an integer representing the smallest number of squares that may be included in the upper-left corner of the partition in all solutions. Sample Input 13 3
10 1 52
20 30 1
1 2 3 Sample Output 13 sample input 24 3
1 1 1 1
1 30 80 2
1 1 1 100 Sample output 210
Do not understand or need to exchange students can powder me Sina Weibo @ Rei, private messages YO!!
every question is written thinking efficiency is too low, there is need or really do not understand go to my Weibo private messages I update blog
Package Com.prev;import Java.util.scanner;public class _4 {public static int n;public static int m;public static int [] Array;public static Boolean [] flag;public static int sum;public static int count = 30;public static void Main (String [] args) {Scanner scan = new Scanner (system.in); m = Scan.nextint (); n = scan.nextint (); sum = 0;array = new Int[n][m];flag = NE W boolean[n][m];for (int i = 0; i < n; i++) for (int j = 0; J < m; J + +) {Array[i][j] = scan.nextint (); sum + = Array[i][j] ;} Flag[0][0] = True;dfs (0,0,1,array[0][0]); System.out.println (count);} private static void Seek (int i, int j, int k,int thissum) {//TODO auto-generated method stubif (sum% 2 = = 0 && t Hissum = = SUM/2) {count = Math.min (count, k);} if (Thissum < SUM/2) {if (J+1 < M &&!flag[i][j+1]) {flag[i][j+1] = True;dfs (i,j+1,k+1,thissum+array[i][j+1] ); flag[i][j+1] = false;} if (I+1 < n &&!flag[i+1][j]) {Flag[i+1][j] = True;dfs (I+1,j,k+1,thissum+array[i+1][j]); flag[i+1][j] = false;} if (j-1 >=0 &&!flag[i][j-1]) {flag[i][j-1] = True;dfs (i,j-1,k+1,thissum+array[i][j-1]); flag[i][j-1] = false;} if (i-1 >=0 &&!flag[i-1][j]) {Flag[i-1][j] = True;dfs (I-1,j,k+1,thissum+array[i-1][j]); Flag[i-1][j] = False ;}}}}
Blue Bridge Cup previous test cut lattice