Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- const int MAX = 60;
- int n, t, o_inx, result, order[50000][10], number[MAX][10], p_order[10];
- bool checkNumber[10];
- void getMax(int x) {
- int out = 0, inx = 1, r = 1, score = 0;
- bool checkBase[5];
- while(r <= n) {
- while(out < 3) {
- if(number[r][order[x][inx]] == 0) {
- out++;
- inx++;
- }
- else if(number[r][order[x][inx]] == 1) {
- for(int i=3;i>=1;i--) {
- if(checkBase[i]) {
- if(i == 3) {
- score++;
- checkBase[i] = false;
- }
- else {
- checkBase[i+1] = true;
- checkBase[i] = false;
- }
- }
- }
- checkBase[1] = true;
- inx++;
- }
- else if(number[r][order[x][inx]] == 2) {
- for(int i=3;i>=1;i--) {
- if(checkBase[i]) {
- if(i >= 2) {
- score++;
- checkBase[i] = false;
- }
- else {
- checkBase[i+2] = true;
- checkBase[i] = false;
- }
- }
- }
- checkBase[2] = true;
- inx++;
- }
- else if(number[r][order[x][inx]] == 3) {
- for(int i=3;i>=1;i--) {
- if(checkBase[i]) {
- score++;
- checkBase[i] = false;
- }
- }
- checkBase[3] = true;
- inx++;
- }
- else if(number[r][order[x][inx]] == 4) {
- for(int i=3;i>=1;i--) {
- if(checkBase[i]) {
- score++;
- checkBase[i] = false;
- }
- }
- score++;
- inx++;
- }
- if(inx == 10) inx = 1;
- }
- r++;
- out = 0;
- memset(checkBase, 0, sizeof(checkBase));
- }
- if(score > result) result = score;
- }
- void DFS(int x) {
- if(x == 10) {
- for(int i=1;i<=9;i++) {
- order[o_inx][i] = p_order[i];
- }
- o_inx++;
- }
- else if(x == 4) {
- p_order[x] = 1;
- DFS(x+1);
- }
- else {
- for(int i=2;i<=9;i++) {
- if(!checkNumber[i]) {
- p_order[x] = i;
- checkNumber[i] = true;
- DFS(x+1);
- p_order[x] = 0;
- checkNumber[i] = false;
- }
- }
- }
- }
- int main() {
- DFS(1);
- scanf("%d", &t);
- for(int v=1;v<=t;v++) {
- scanf("%d", &n);
- for(int i=1;i<=n;i++) {
- for(int j=1;j<=9;j++) {
- scanf("%d", &number[i][j]);
- }
- }
- for(int i=0;i<o_inx;i++) {
- getMax(i);
- }
- printf("%d %d\n", v, result);
- result = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement