SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | using namespace std; | |
| 3 | ||
| 4 | - | static int sum[3][3] = {0};
|
| 4 | + | int ky(int input[3][3]){
|
| 5 | int sum[3][3] = {0};
| |
| 6 | - | int ky(int a[3][3]){
|
| 6 | + | int a[3][3] = {0};
|
| 7 | - | int store[9] = {0};
|
| 7 | + | |
| 8 | - | int k = 0; |
| 8 | + | |
| 9 | for(int j = 0; j < 3; j++){
| |
| 10 | a[i][j] = input[(i+1)%3][j]+input[(i+2)%3][j]; | |
| 11 | } | |
| 12 | - | store[k] = a[(i+1)%3][j]+a[(i+2)%3][j]; |
| 12 | + | |
| 13 | - | k++; |
| 13 | + | |
| 14 | for(int j = 0; j < 3; j++){
| |
| 15 | sum[i][j] = min(a[(i+1)%3][(j+1)%3]+a[(i+2)%3][(j+2)%3],a[(i+1)%3][(j+2)%3]+a[(i+2)%3][(j+1)%3]); | |
| 16 | sum[i][j] += a[i][j]; | |
| 17 | } | |
| 18 | - | a[i][j] = store[i*3+j]; |
| 18 | + | |
| 19 | - | |
| 19 | + | |
| 20 | for(int j = 0; j < 3; j++){
| |
| 21 | res = min((int)res,sum[i][j]); | |
| 22 | } | |
| 23 | } | |
| 24 | return res; | |
| 25 | } | |
| 26 | ||
| 27 | int main() {
| |
| 28 | int arr[3][3] = {{5,10,5},{20,10,5},{10,20,10}};
| |
| 29 | cout << ky(arr); | |
| 30 | return 0; | |
| 31 | } |