Suppose that you are playing a card game whose goal is to collect exactly k cards with a total
value of t. Write a solution that can determine if it is possible for a given collection of cards
whose values are given in the array values. For example, if the array contained the values
<10,5,7,2>, k = 3, and t = 12, you would return false because no three values add to 12.
However, if t = 14, you would return true, since 5 + 7 + 2 = 14.
So I considered this to be a form of groupSum recursion, so I try to implement it in recursion form. However, since the passing parameters are not the incrementing level index but 'k' that is the limit number of the numbers we can choose from the array, I cannot use passing index through recursion to search from the start of the array toward the end of the values.length(the length of the array). would there be any method I can use to increment and search along the array using k, the number of numbers we can add into the total(t) instead of the increment of the index from the start?
kind of code I am trying to make in Java:
public static boolean isWinnable(int[] values, int k, int t) {
if (k == 0) {
return t == 0;
}
if (isWinnable(values, k - 1?, t)) { #recursion that is going to apply current index value
return true;
}
if (isWinnable(values, k - 1?, t - values[?])) { #recursion that is not going to apply current index value
return true;
}
return false;
}
}
Step by stepSolved in 2 steps with 2 images
- Using a Java program solve the following problem using arrays: Past A: Coupon collector is a classic statistic problem with many practical applications. The problem is to pick objects from a set of objects repeatedly and determine how many picks are needed for all the objects to be picked at least once. A variation of the problem is to pick cards from a shuffled deck of 52 cards repeatedly and find out how many picks are needed before you see one of each suit. Assume a picked card is placed back in the deck before picking another. Write a program to simulate the number of picks needed to get total of four cards from each different suit and display the four cards picked (it is possible that a card may be picked twice). Here is a sample run of the program: Queen of Spades 5 of Clubs Queen of Hearts 4 of Diamonds Number of picks: 12 Sample run explanation: As you see in the above run, 12 picks are made to get the four cards from different suits. The other 8 picks (12-4-8) were from the…arrow_forwardWrite in javaarrow_forwardIn java language using arrays This method examines the two-dimensional array of integersidentified by the first parameter, whose length (number of rows,also the number of students) is the second parameter, while thethree columns in the array represent the scores for threedifferent tests.The test scores for each student (one row of three grades) arecombined to find the average score for each student. The integerreturned is the number of students with a test average less than 70. @param numStudents, the number of students who took the three tests@param theArray, a 2-D array of integer scores@return, the number of test averages below a score of 70*/public static int testAverage(double[][] theArray, int numStudents){int NUM_TESTS = 3; // your work here // loop though theArray, computing each student's average // your work here// return count of averages below 70.0 // your work herearrow_forward
- The programming language used is Javaarrow_forwardA popular word game involves finding words from a grid of randomly generatedletters. Words must be at least three letters long and formed from adjoining letters.Letters may not be reused and it is valid to move across diagonals. As an example,consider the following 4 * 4 grid of letters: A B C DE F G HI J K LM N O P The word “FAB” is valid (letters in the upper left corner) and the word “KNIFE”is valid. The word “BABE” is not valid because the “B” may not be reused. Theword “MINE” is not valid because the “E” is not adjacent to the “N”. Write a program that uses a 4 * 4 two-dimensional array to represent the gameboard. The program should randomly select letters for the board. You may wishto select vowels with a higher probability than consonants. You may also wish toalways place a “U” next to a “Q” or to treat “QU” as a single letter. The programshould read the words from the text file words.txt (included on the website withthis book) and then use a recursive algorithm to…arrow_forwardThe programming language used is Javaarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY