using System namespace ArrayTask class MainClass public static void Ma

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
namespace ArrayTask {
class MainClass {
public static void Main(string[] args) {
int[][] array = new int[3][] {
new int[] {1, 2, 3, 4},
new int[] {5, 6, 7, 8},
new int[] {9, 10, 11, 12}
};
int[][] temp = new int[3][];
for (int i = 0; i < 3; i++) {
temp[i] = new int[4];
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
temp[i][j] = 0;
}
}
temp[0][1] = array[0][0] + array[0][1];
temp[1][0] = array[0][0] + array[1][0];
for (int i = 2; i < 4; i++) {
temp[0][i] = array[0][i] + temp[0][i - 1];
}
for (int i = 2; i < 3; i++) {
temp[i][0] = array[i][0] + temp[i - 1][0];
}
for (int i = 1; i < 3; i++) {
for (int j = 1; j < 4; j++) {
temp[i][j] = array[i][j] + temp[i][j - 1];
}
}
for (int i = 1; i < 4; i++) {
for (int j = 1; j < 3; j++) {
int value = array[j][i] + temp[j - 1][i];
if (value < temp[j][i])
temp[j][i] = value;
}
}
Console.WriteLine("Result: " + temp[2][3]);
}
}
}