Untitled
unknown
plain_text
8 months ago
2.5 kB
4
Indexable
import java.io.FileInputStream;
import java.util.Scanner;
// PIZZA
public class CanhGac {
static int T;
static int k;
static int r;
static int m;
static int[][] posRes = new int[20][2];
static int n;
static int[][] posCus = new int[100][3];
static int result;
static boolean[][] visitedCus = new boolean[2000][2000];
static boolean visited[] = new boolean[20];
static void backtrack(int x, int count, int customer) {
if (x > m) return;
if (count == k) {
for (int i = 0; i < m; i++) {
if (visited[i]) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
}
System.out.println();
if (customer > result) result = customer;
return;
}
/// chon
/// ban kinh = r
/// xCuahang = posRes[x][0]
/// yCuahang = posRes[x][1]
int total = 0;
int[][] cusTrue = new int[100][2];
int len = 0;
for (int i = 0; i < n; i++) {
if (Math.pow((posRes[x][0] - posCus[i][0]), 2) + Math.pow((posRes[x][1] - posCus[i][1]), 2) <= r*r && !visitedCus[posCus[i][0]][posCus[i][1]]) {
visitedCus[posCus[i][0]][posCus[i][1]] = true;
total += posCus[i][2];
cusTrue[len][0] = posCus[i][0];
cusTrue[len][1] = posCus[i][1];
len++;
}
}
visited[x] = true;
backtrack(x+1, count + 1, customer + total);
visited[x] = false;
for (int i = 0; i < len; i++) {
visitedCus[cusTrue[i][0]][cusTrue[i][1]] = false;
}
/// ko chon
backtrack(x+1, count, customer);
}
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("src/input.txt"));
Scanner sc = new Scanner(System.in);
T = sc.nextInt();
for (int tc = 1; tc <= T; tc++) {
k = sc.nextInt();
r = sc.nextInt();
m = sc.nextInt();
for (int i = 0; i < m; i++) {
posRes[i][0] = sc.nextInt() + 1000;
posRes[i][1] = sc.nextInt() + 1000;
}
n = sc.nextInt();
for (int i = 0; i < n; i++) {
posCus[i][0] = sc.nextInt() + 1000;
posCus[i][1] = sc.nextInt() + 1000;
posCus[i][2] = sc.nextInt();
}
result = 0;
backtrack(0, 0, 0);
System.out.println(result);
}
sc.close();
}
}Editor is loading...
Leave a Comment