모든 미노의 경우의 수를 Brute Force하면 됩니다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Mino
{
public:
Mino (const int n0, const int n1
, const int n2, const int n3
, const int n4, const int n5
, const int n6, const int n7
, const vector<vector<int>>& InBoard)
: Board(InBoard)
{
Blocks.resize(4);
Blocks[0].first = n0;
Blocks[0].second = n1;
Blocks[1].first = n2;
Blocks[1].second = n3;
Blocks[2].first = n4;
Blocks[2].second = n5;
Blocks[3].first = n6;
Blocks[3].second = n7;
}
private:
vector<pair<int, int>> Blocks;
const vector<vector<int>>& Board;
public:
void Locate(const int i, const int j)
{
const int firstDiff = i - Blocks[0].first;
const int secondDiff = j - Blocks[0].second;
for (pair<int, int>& pair : Blocks)
{
pair.first += firstDiff;
pair.second += secondDiff;
}
}
bool IsValid() const
{
for(const pair<int, int>& pair : Blocks)
{
if (0 > pair.first or
pair.first >= Board.size())
{
return false;
}
if(0 > pair.second or
pair.second >= Board[0].size())
{
return false;
}
}
return true;
}
int GetSum() const
{
int result = 0;
for (const pair<int, int>& pair : Blocks)
{
result += Board[pair.first][pair.second];
}
return result;
}
};
int main()
{
int N;
int M;
string intputString;
cin >> N;
cin >> M;
vector<vector<int>> borad = vector<vector<int>>(N, vector<int>(M, 0));
for(int i = 0; i < N; ++i)
{
for(int j = 0; j < M; ++j)
{
cin >> borad[i][j];
}
}
vector<Mino> Minos;
//l
Minos.push_back(
Mino(
0, 0,
0, 1,
0, 2,
0, 3,
borad));
Minos.push_back(
Mino(
0, 0,
1, 0,
2, 0,
3, 0,
borad));
//O
Minos.push_back(
Mino(
0, 0,
1, 0,
0, 1,
1, 1,
borad));
//L
Minos.push_back(
Mino(
0, 0,
1, 0,
2, 0,
2, 1,
borad));
Minos.push_back(
Mino(
1, 0,
1, 1,
1, 2,
0, 2,
borad));
Minos.push_back(
Mino(
1, 0,
0, 0,
0, 1,
0, 2,
borad));
Minos.push_back(
Mino(
0, 0,
0, 1,
1, 1,
2, 1,
borad));
//J
Minos.push_back(
Mino(
0, 1,
1, 1,
2, 1,
2, 0,
borad));
Minos.push_back(
Mino(
0, 0,
0, 1,
0, 2,
1, 2,
borad));
Minos.push_back(
Mino(
0, 0,
1, 0,
1, 1,
1, 2,
borad));
Minos.push_back(
Mino(
0, 1,
0, 0,
1, 0,
2, 0,
borad));
//S
Minos.push_back(
Mino(
0, 0,
1, 0,
1, 1,
2, 1,
borad));
Minos.push_back(
Mino(
1, 0,
1, 1,
0, 1,
0, 2,
borad));
//Z
Minos.push_back(
Mino(
0, 0,
0, 1,
1, 1,
1, 2,
borad));
Minos.push_back(
Mino(
0, 1,
1, 1,
1, 0,
2, 0,
borad));
//T
Minos.push_back(
Mino(
0, 0,
0, 1,
0, 2,
1, 1,
borad));
Minos.push_back(
Mino(
0, 0,
1, 0,
2, 0,
1, 1,
borad));
Minos.push_back(
Mino(
1, 0,
1, 1,
1, 2,
0, 1,
borad));
Minos.push_back(
Mino(
0, 1,
1, 1,
2, 1,
1, 0,
borad));
int max = 0;
for(int k = 0; k < Minos.size(); ++k)
{
for (int i = 0; i < N; ++i)
{
for(int j = 0; j < M; ++j)
{
Minos[k].Locate(i, j);
if(Minos[k].IsValid())
{
const int result = Minos[k].GetSum();
if(result > max)
{
max = result;
}
}
}
}
}
cout << max;
return 0;
}