1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pochemuha
4 years ago
11

Given an N x M matrix and a dictionary containing K distinct words of length between 1 and 30 symbols, the Word Search should re

turn all the words you can get from the matrix that are contained in the dictionary. There are rules: You can start from any cell in the matrix and go up, down, to the left, and to the right (not leaving the matrix) to collect letters for the word. Your "path" should not cross itself, i.e., a cell in the matrix cannot be visited more than once. You need to return the array of words found. There is no need to return the "paths" for them.
Engineering
1 answer:
Ket [755]4 years ago
8 0

Answer:

import java.util.*;

public class Main {

  public static String[] wordSearch(char[][] matrix, String[] words) {

      int N = matrix.length;

      List<String> myList = new ArrayList<String>();

      int pos = 0;

      for(String word : words)

      {

      for (int i = 0; i < N; i++) {

          for (int j = 0; j < N; j++) {

              if (search(matrix, word, i, j, 0, N)) {

              if(!myList.contains(word))

              {

              myList.add(word);

              }

              }

          }

      }

      }

     

      String[] newDict = myList.toArray(new String[myList.size()]);

     

  return newDict;

  }

  public static boolean search(char[][] matrix, String word, int row, int col,

          int index, int N) {

      // check if current cell not already used or character in it is not not

      if (word.charAt(index) != matrix[row][col]) {

          return false;

      }

      if (index == word.length() - 1) {

          // word is found, return true

          return true;

      }

             

      // check if cell is already used

      if (row + 1 < N && search(matrix, word, row + 1, col, index + 1, N)) { // go

                                                                              // down

          return true;

      }

      if (row - 1 >= 0 && search(matrix, word, row - 1, col, index + 1, N)) { // go

                                                                              // up

          return true;

      }

      if (col + 1 < N && search(matrix, word, row, col + 1, index + 1, N)) { // go

                                                                              // right

          return true;

      }

      if (col - 1 >= 0 && search(matrix, word, row, col - 1, index + 1, N)) { // go

                                                                              // left

          return true;

      }

      if (row - 1 >= 0 && col + 1 < N

              && search(matrix, word, row - 1, col + 1, index + 1, N)) {

          // go diagonally up right

          return true;

      }

      if (row - 1 >= 0 && col - 1 >= 0

              && search(matrix, word, row - 1, col - 1, index + 1, N)) {

          // go diagonally up left

          return true;

      }

      if (row + 1 < N && col - 1 >= 0

              && search(matrix, word, row + 1, col - 1, index + 1, N)) {

          // go diagonally down left

          return true;

      }

      if (row + 1 < N && col + 1 < N

              && search(matrix, word, row + 1, col + 1, index + 1, N)) {

          // go diagonally down right

          return true;

      }

      // if none of the option works out, BACKTRACK and return false

         

      return false;

  }

  public static void main(String[] args) {

      char[][] matrix = { { 'j', 'a', 's' },

              { 'a', 'v', 'o'},

              { 'h', 'a', 'n'} };

 

  String[] arr_str = {"a", "java", "vaxn", "havos", "xsds", "man"};

 

     

      arr_str = wordSearch(matrix, arr_str);

     

      for(String str : arr_str)

      {

      System.out.println(str);

      }

  }

}

You might be interested in
What are the ropes of secretaries and treasures in a meeting​
Nastasia [14]

Answer:

To prepare and issue notices and agendas of all meetings in consultation with the chairman, and to ensure that any background papers are available well before the meeting. To attend and take the minutes of every committee meeting. To circulate minutes to all committee members, and to conduct the correspondence

Explanation:

I think you want to say roles.

4 0
3 years ago
Need help with these ez questions will mark brainiest
denpristay [2]

Hi! Here's the answers!

True

C

True

8 0
3 years ago
Read 2 more answers
1.00-L insulated bottle is full of tea at 90.08°C. You pour out one cup of tea and immediately screw the stopper back on the bot
liberstina [14]

Answer:

T_{f} = 90.07998 ° C

Explanation:

This is a calorimetry process where the heat given by the Te is absorbed by the air at room temperature (T₀ = 25ºC) with a specific heat of 1,009 J / kg ºC, we assume that the amount of Tea in the cup is V₀ = 100 ml. The bottle being thermally insulated does not intervene in the process

                 Qc = -Qb

                M c_{e_Te} (T₁ -T_{f}) = m c_{e_air} (T_{f}-T₀)

Where M is the mass of Tea that remains after taking out the cup, the density of Te is the density of water plus the solids dissolved in them, the approximate values are from 1020 to 1200 kg / m³, for this calculation we use 1100 kg / m³

   ρ = m / V  

   V = 1000 -100 = 900 ml  

   V = 0.900 l (1 m3 / 1000 l) = 0.900 10⁻³ m³  

   V_air = 0.100 l = 0.1 10⁻³ m³  

Tea Mass  

     M = ρ V_te  

     M = 1100 0.9 10⁻³  

     M = 0.990 kg  

Air mass  

     m = ρ _air V_air  

     m = 1.225 0.1 10⁻³  

     m = 0.1225 10⁻³ kg  

(m c_{e_air} + M c_{e_Te}) T_{f}. = M c_{e_Te} T1 - m c_{e_air} T₀  

T_{f} = (M c_{e_Te} T₁ - m c_{e_air} T₀) / (m c_{e_air} + M c_{e_Te})  

Let's calculate  

T_{f} = (0.990 1100 90.08– 0.1225 10⁻³ 1.225 25) / (0.1225 10⁻³ 1.225 + 0.990 1100)  

T_{f} = (98097.12 -3.75 10⁻³) / (0.15 10⁻³ +1089)  

T_{f} = 98097.11 / 1089.0002  

T_{f} = 90.07998 ° C  

This temperature decrease is very small and cannot be measured

3 0
3 years ago
The screw of shaft straightener exerts a load of 30 as shown in Figure . The screw is square threaded of outside diameter 75 mm
kykrilka [37]

Answer:

See calculation below

Explanation:

Given:

W = 30 kN = 30x10³ N

d = 75 mm

p = 6 mm

D = 300 mm

μ = tan Φ = 0.2

<u><em>1. Force required at the rim of handwheel </em></u>

Let P₁ = Force required at the rim of handwheel

Inner diameter or core diameter of the screw = dc = do - p = 75 - 6 = 69 mm

Mean diameter of screw:    *d = \frac{do + dc}{2} = (75 + 69) / 2 = 72 mm

and

tan α = p / πd  =  6 / (π x 72)  =  0.0265

∴ Torque required to overcome friction at he threads is  T = P x d/2

T = W tan (α + Ф) d/2

T =  W(\frac{tan \alpha + tan \theta}{1 - tan \alpha + tan \theta } ) * \frac{d}{2}

T = 30x10³ * ((0.0265 + 0.2) / (1 - 0.0265 x 0.2)) x 72/2

T = 245,400 N-mm

We know that the torque required at the rim of handwheel (T)

245,400 = P1 x D/2 = P1 x (300/2) = 150 P1

P1 = 245,400 / 150

P1 = 1636 N

<u><em>2. Maximum compressive stress in the screw</em></u>

                         30x10³

Qc = W / Ac = -------------- = 8.02 N/mm²

                      π/4 * 69²

Qc = 8.02 MPa

Bearing pressure on the threads (we know that number of threads in contact with the nut)

n = height of nut / pitch of threads = 150 / 6 = 25 threads

thickness of threads, t = p/2 = 6/2 = 3 mm

bearing pressure on the threads = Pb = W / (π d t n)

Pb = 30 x 10³ / (π * 72 * 3 * 25)

Pb = 1.77 N/mm²

Max shear stress on the threads = τ = 16 T / (π dc³)

τ = (16 * 245,400) / ( π * 69³ )

τ = 3.8 M/mm²

*the mean dia of the screw (d) = d = do - p/2 = 75 - 6/2 = 72

∴max shear stress in the threads τmax = 1/2 * sqrt(8.02² + (4 * 3.8²))

τmax = 5.5 Mpa

<u><em>3. efficiency of the straightener</em></u>

<u><em></em></u>

To = W tan α x d/2 = 30x10³ * 0.0265 * 72/2 = 28,620 N-mm

∴Efficiency of the straightener is η =  To / T = 28,620 / 245,400

η = 0.116 or 11.6%

4 0
3 years ago
The Industrial Age was ushered in by the invention of the steam engine. What did this invention lead to?
alisha [4.7K]

Answer: The introduction of steam engines improved productivity and technology, and allowed the creation of smaller and better engines.

Explanation: Obviously steam engines were revolutionary for our time. The more you focus on something, the better you can understand. Therefore allowing you to advance in your studies.

4 0
4 years ago
Other questions:
  • The cost of fixing a fault for a software product identified during the implementation phase is approximated at $32,000 USD. How
    9·1 answer
  • The entrance of the space module into atmosphere is one of the very critical phases of any space mission. Due to the formation o
    6·1 answer
  • Find the diameter of the test cylinder in which 6660 N force is acting on it with a modulus of elasticity 110 x 103 Pa. The init
    15·1 answer
  • Ihjpr2 ywjegnak'evsinawhe2'qwmasnh ngl,;snhy
    9·2 answers
  • Words and numbers can be<br> printed using many different<br> or type styles.
    14·1 answer
  • Which of the following best describes the basic purpose of the internet?
    7·2 answers
  • A solid circular cylinder of mass m, radius r, and length l is pivoted about a transverse axis
    12·1 answer
  • fdkgdsvdgvdfgvsdcvbfbfdbvfdbsdvbesgvdslgfkrledmgoskflodjgloerjgvoljgegjp;erorf;wgp;kiaers;ogjo;rhgerjfrejgfdlhodjglodjheihtgo;rg
    13·1 answer
  • Which option distinguishes the requirement standard most associated with the following statement?
    8·1 answer
  • Construction support involves mostly what kind of work?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!