Untitled
unknown
plain_text
2 years ago
1.7 kB
5
Indexable
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class SkyForce { static int N, map[][], ans, visit[][]; static int dx[] = { -1, -1, -1 }; static int dy[] = { -1, 0, 1 }; public static void main(String[] args) { try { System.setIn(new FileInputStream("SkyForce")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int tc = 1; tc <= T; tc++) { N = sc.nextInt(); map = new int[N][5]; for (int i = 0; i < N; i++) { for (int j = 0; j < 5; j++) { map[i][j] = sc.nextInt(); } } visit = new int[N][5]; ans = -1; for (int i = 0; i <= 5; i++)// chi tha bom trong doan nay { BT(N, 2, 0, i); // truyen bom i } System.out.println("Case #" + tc); System.out.println(ans); } } public static void BT(int x, int y, int xu, int bom) { // int bom: gsu vi // tri tha bom if (x <= 0) { // if (xu < 0) // return; // else { ans = Math.max(ans, xu); return; // } } if (xu < 0) return; for (int i = 0; i < 3; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx >= 0 && xx < N && yy >= 0 && yy < 5) { if (map[xx][yy] == 0) BT(xx, yy, xu, bom); else if (map[xx][yy] == 1) BT(xx, yy, xu + 1, bom); else { if (xx >= bom && xx < bom + 5) // gia su tha bom tai xx // >=bom! BT(xx, yy, xu, bom); else // k tha bom tru quan dich BT(xx, yy, xu - 1, bom); } } } } }
Editor is loading...