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
bulgar [2K]
4 years ago
9

You will be given a value of n and k, one line each. You will write a program that determines the minimum number of probe attemp

ts in the worst case before you determine the correct day. Your output should be a single number that represents the minimum number of probes.
Computers and Technology
1 answer:
Natalija [7]4 years ago
4 0

Answer:

The written program is in the explanation

Explanation:

RomanticDays.java

import java.util.Scanner;

class RomanticDays {

  static int max(int a, int b) {

      return (a > b) ? a : b;    }

  static int minAttempt(int k, int n) {

      int romancticDays[][] = new int[k+1][n+1];

      int res;

      int loop1,loop2,i;

      for (loop1 = 1; loop1 <= k; loop1++) {

          romancticDays[loop1][1] = 1;

          romancticDays[loop1][0] = 0;    }

      for (loop2 = 1; loop2 <= n; loop2++)

          romancticDays[1][loop2] = loop2;

      for (loop1 = 2; loop1 <= k; loop1++) {

          for (loop2 = 2; loop2 <= n; loop2++) {

              romancticDays[loop1][loop2] = Integer.MAX_VALUE;

              for (i = 1; i <= loop2; i++) {

                  res = 1 + max(romancticDays[loop1 - 1][i - 1], romancticDays[loop1][loop2 - i]);

                  if (res < romancticDays[loop1][loop2])

                      romancticDays[loop1][loop2] = res;  

        }

          }

      }

      return romancticDays[k][n];

  }

  /* Driver program to test */

  public static void main(String args[]) {

      int n,k;

      System.out.print("Enter the value of N and k :");

      Scanner sc=new Scanner(System.in);

      n=sc.nextInt();

      k=sc.nextInt();

      System.out.println( minAttempt(k,n));

}

}

You might be interested in
Given two character strings s1 and s2. Write a Pthread program to find out the number of substrings, in string s1, that is exact
anyanavicka [17]

Answer:

Explanation:

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#define MAX 1024

int total = 0 ;

int n1, n2;

char s1, s2;

FILE fp;

int readf(FILE fp)

{

 if((fp=fopen("strings.txt", "r"))==NULL) {

   printf("ERROR: can’t open string.txt!\n");

   return 0;

 }

 s1=(char)malloc(sizeof(char)MAX);

 if(s1==NULL) {

   printf("ERROR: Out of memory!\n");

   return 1;

 }

 s2=(char)malloc(sizeof(char)MAX);

 if(s1==NULL) {

   printf("ERROR: Out of memory!\n");

   return 1;

 }

 /* read s1 s2 from the file */

 s1=fgets(s1, MAX, fp);

 s2=fgets(s2, MAX, fp);

 n1=strlen(s1); /* length of s1 */

 n2=strlen(s2)-1; /* length of s2 */

 if(s1==NULL || s2==NULL || n1<n2) /* when error exit */

   return 1;

}

int num_substring(void)

{

 int i, j, k;

 int count;

 for(i=0; i<=(n1-n2); i++) {

   count=0;

   for(j=i, k=0; k<n2; j++, k++){ /* search for the next string of size of n2 */

   if((s1+j)!=(s2+k)) {

     break;

   }

   else

     count++;

   if(count==n2)

     total++; /* find a substring in this step */

   }

 }

 return total;

}

int main(int argc, char argv[])

{

 int count;

 readf(fp);

 count=num_substring();

 printf("The number of substrings is: %d\n", count);

 return 1;

}

3 0
3 years ago
Which formulas would work to combine cells with first, middle, and last names from columns A through C and row 2 into a new cell
ryzh [129]

Answer:

=CONCATENATE(A2," ",B2," "C2)

Explanation:

The concatenate function in excel can be used to combine inputs in two or more cells.

The formula =CONCATENATE(A2," ",B2," "C2) could be explained thus :

'=' All excel functions starts with the = sign

'Concatenate' the function which allows us to combine

A2 = column A row 2

B2 = column B row 2

C2 = column C row 2

" " means a space after each cell input.

8 0
3 years ago
Read 2 more answers
Write a C# Console application that converts a mile into its equivalent metric kilometer measurement. The program asks the user
zzz [600]

Answer:

Following are the program in c#

using System;  // namespace system

using System.Collections.Generic;  // namespace collection

using System.Linq;

using System.Text;

namespace test // namespace

{

   class Program1 // class

   {        

                 

       static void Main(string[] args) // Main function

       {

           double nMiles, nKm;

           Console.Write("Enter Value In Miles : ");

           nMiles =Convert.ToDouble(Console.ReadLine());

           nKm = (nMiles / 0.62137);

           Console.WriteLine("Output:");

           Console.WriteLine("Value In Miles :" + nMiles);

           Console.WriteLine("Value In KM :" + nKm);

           Console.Read();

       }

   }

}

Output:

Case A-

Enter Value In Miles : 10

Value In Miles : 10

Value In KM : 16.09347

Case B-

Enter Values In Miles : 3.25

Value In Miles : 3.25

Value In KM : 5.230378

Explanation:

Here we take a input value in "nMiles" variable and converted into a Km. that will stored in "nkm" variable  . To convert miles into km we use  calculative formula Km=(miles/0.62137). This formula convert the entered value into km and finally print the value of miles and km miles variable.

4 0
3 years ago
WILL GIVE BRAINLIEST!!! 15 POINTS!! HELPPPP!!
Rudiy27

Answer:

B and C both will be right answers

5 0
3 years ago
Cyberbullying can negatively impact a victim’s <br> well-being.
vekshin1

Answer:

whats the questions

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is an example of a good URL?
    7·2 answers
  • What allows a person to interact with web browser software?
    13·2 answers
  • How to block someone from watching your youtube videos?
    12·2 answers
  • What role does normalization play in good and bad table structures, and why is normalization so important to a good table struct
    11·1 answer
  • Edible vaccines, a more controversial approach to vaccine development, have been investigated by scientists. Plants can be genet
    6·1 answer
  • Fred wants to analyze his spending habits of the past few years and has gathered information on the checks he has written from 2
    6·1 answer
  • Write a program that prompts the user to enter a series of numbers between 0 and 10 asintegers. The user will enter all numbers
    6·1 answer
  • Which browser feature will delete your history, cache, and cookies the moment you close the special window
    6·1 answer
  • What does a computer monitor look like when struck really hard?
    15·1 answer
  • What is the purpose of installing updates on your computer?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!