public long numWays(int width, int height, String[] bad) { dpTable = new long[width][height]; final boolean valid[][] = new boolean[width][height]; for (int i = 0; i < width; ++i) { Arrays.fill(dpTable[i], -1l); Arrays.fill(valid[i], true); } dpTable[0][0] = 0l; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) {} } return 0l; }
public static void main(String[] args) { Scanner inp = new Scanner(System.in); int n = inp.nextInt(); String[] store = new String[n]; for (int i = 0; i < n; i++) store[i] = inp.next(); int[] cnt = new int[n]; Arrays.fill(cnt, 0); String str = inp.next(); for (int j = 0; j < n; j++) { int l1 = store[j].length(); for (int k = 0; k <= (str.length() - l1); k++) { if (str.substring(k, k + l1).equals(store[j])) { cnt[j] = cnt[j] + 1; } } } int y = 0; for (int m = 0; m < n; m++) { y = Math.max(y, cnt[m]); } System.out.println(y); for (int h = 0; h < n; h++) { if (cnt[h] == y) System.out.println(store[h]); } }
public static void solve() { int cases = scan.nextInt(); scan.nextLine(); for (int caze = 1; caze <= cases; caze++) { out.print("Case #" + caze + ": "); for (int i = 0; i < MAX; i++) Arrays.fill(memo[i], -1); str = scan.nextLine().toCharArray(); out.println(go(0, str.length) ? "YES" : "NO"); } }
static void solve() { for (int i = 0; i < MAX; i++) choose[i][0] = choose[i][i] = 1; for (int i = 1; i < MAX; i++) for (int j = 1; j < i; j++) choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % MOD; for (int i = 0; i < MAX; i++) Arrays.fill(memo[i], -1); Scanner scan = new Scanner(in); int T = scan.nextInt(); for (int t = 1; t <= T; t++) { out.print("Case #" + t + ": "); int n = scan.nextInt(); int ways = 0; for (int i = 1; i < n; i++) ways = (ways + go(i, n)) % MOD; out.println(ways); } }
public int bfs() { int[] record = new int[n]; Arrays.fill(record, Integer.MAX_VALUE); LinkedList<Integer> queue = new LinkedList<Integer>(); queue.addLast(0); int distance = 0; int count = 1; while (queue.size() > 0) { int newCount = 0; while (count > 0) { int tempPoint = queue.pollFirst(); ArrayList<Road> tempRoads = roads[tempPoint]; } distance++; } }
public Main() { try { in = new BufferedReader(new InputStreamReader(System.in)); // minimum distance from D to K int numCities = nextInt(); int tradeRoutes = nextInt(); int[][] adjacencyMatrix = new int[numCities][numCities]; int[] minDistance = new int[numCities]; Arrays.fill(minDistance, 100000000); // Arrays.fill(adjacencyMatrix, -1); // int [] pencilCosts = new int[ Node[] cities = new Node[numCities]; for (int x = 0; x < tradeRoutes; x++) { int cityA = nextInt() - 1; int cityB = nextInt() - 1; int cost = nextInt(); if (cities[cityA] == null) cities[cityA] = new Node(cityA); if (cities[cityB] == null) cities[cityB] = new Node(cityB); adjacencyMatrix[cityA][cityB] = cost; adjacencyMatrix[cityB][cityA] = cost; // cities[cityA].routes.add(new Edge(cost, cities[cityB])); // cities[cityB].routes.add(new Edge(cost, cities[cityA])); } int numStores = nextInt(); int[] pencilCosts = new int[numCities]; Arrays.fill(pencilCosts, -1); for (int x = 0; x < numStores; x++) { int ID = nextInt() - 1; int cost = nextInt(); pencilCosts[ID] = cost; } int destination = nextInt() - 1; // if (isGood[destination]){ // } int minCost = 100000000; Queue<Node> Q = new LinkedList<Node>(); // PriorityQueue<Node> Q = new PriorityQueue<Node>(); minDistance[destination] = 0; // cities[destination].distance = 0; Q.offer(cities[destination]); while (!Q.isEmpty()) { Node temp = Q.poll(); for (int x = 0; x < numCities; x++) { if (adjacencyMatrix[temp.ID][x] != 0 && (minDistance[x] == 100000000 || minDistance[x] > minDistance[temp.ID] + adjacencyMatrix[temp.ID][x])) { minDistance[x] = minDistance[temp.ID] + adjacencyMatrix[temp.ID][x]; if (pencilCosts[x] != -1 && minDistance[x] < minCost) { // System.out.println(minCost); minCost = Math.min(minDistance[x] + pencilCosts[x], minCost); Q.offer(cities[x]); } else { if (pencilCosts[x] == -1) { // why> Q.offer(cities[x]); } } // Q.offer(temp.routes.get(x).destination); } } } for (int x = 0; x < numCities; x++) { if (pencilCosts[x] != -1 && pencilCosts[x] + minDistance[x] < minCost && minDistance[x] != 100000000) { minCost = minDistance[x] + pencilCosts[x]; } } System.out.println(minCost); } catch (IOException e) { System.out.println("IO: General"); } }