貪欲
class ColoredStrokes { public: int getLeast(vector <string> P) { int cnt = 0; const int h = P.size(), w = P[0].size(); bool b[h][w]; bool r[h][w]; fill(&b[0][0], &b[h - 1][w], false); fill(&r[0][0], &r[h - 1][w], false); for (int i = 0; i < (int)P.size(); ++i) { for (int j = 0; j < (int)P[i].size(); ++j) { if (b[i][j]) continue; if (P[i][j] == 'B' || P[i][j] == 'G') ; else continue; ++cnt; for (int k = i; k < (int)h; ++k) { if (P[k][j] == 'B' || P[k][j] == 'G') ; else break; b[k][j] = true; } } } for (int i = 0; i < (int)P.size(); ++i) { for (int j = 0; j < (int)P[i].size(); ++j) { if (r[i][j]) continue; if (P[i][j] == 'R' || P[i][j] == 'G') ; else continue; ++cnt; for (int k = j; k < (int)w; ++k) { if (P[i][k] == 'R' || P[i][k] == 'G') ; else break; r[i][k] = true; } } } return cnt; } };