# Untitled

unknown
plain_text
19 days ago
1.9 kB
1
Indexable
Never
```#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

class Position {
public:
int x, y;

Position(int x, int y) : x(x), y(y) {}
};

int n, m, col, maxScore, sum;
int arr[101][101];
bool visited[101][101];
int spinX[] = { -1, -2, -2, -1 };
int spinY[] = { -2, -1, 1, 2 };

void tinhdiem(int arr[]) {
sum = 0;
sum += arr[0] * 5;
if (arr[1] < 3) {
sum += arr[1] * 10;
}
else if (arr[1] >= 3 && arr[1] < 6) {
sum += 50;
sum += 10 * (arr[1] - 3);
}
else if (arr[1] >= 6) {
sum += (arr[1] / 6) * 150;
sum += (arr[1] % 6) * 10;
}
if (arr[2] == 1) {
sum += 30;
}
else if (arr[2] > 0) {
sum += (arr[2] / 2) * 100;
sum += (arr[2] % 2) * 30;
}
if (arr[3] == 1) {
sum += 20;
}
else if (arr[3] == 2) {
sum += 50;
}
else if (arr[3] == 3) {
sum += 100;
}
else if (arr[3] == 4) {
sum += 200;
}
else if (arr[3] >= 5) {
sum += 500;
}
if (arr[4] == 1 && arr[5] == 1) {
sum += 1000;
}
if (arr[6] == 1) {
sum += 1;
}
}

void Try(int r, int c, int arr1[]) {
if (arr1[4] == 1 && arr1[5] == 0) {
return;
}
if (r == 1) {

if (arr[r][c] == 6) {
tinhdiem(arr1);
maxScore = max(sum, maxScore);
}
return;
}

for (int i = 0; i < 4; i++) {
int nr = r + spinX[i];
int nc = c + spinY[i];
if (nr > 0 && nr <= n && nc > 0 && nc <= m && !visited[nr][nc]) {
visited[nr][nc] = true;
arr1[arr[nr][nc]]++;
Try(nr, nc, arr1);
arr1[arr[nr][nc]]--;
visited[nr][nc] = false;
}
}
}

int main() {
freopen("input.txt", "r", stdin);
int tc;
cin >> tc;

for (int Case = 1; Case <= tc; Case++) {
cin >> n >> m >> col;

for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> arr[i][j];
}
}

maxScore = 0;
sum = 0;
int arr1[7] = { 0 };
visited[n][col] = true;
arr1[arr[n][col]]++;
Try(n, col, arr1);

cout << "Case #" << Case << endl;
cout << maxScore << endl;
}

return 0;
}```