Question

JAVA Cricket County Selections (100 Marks) A local cricket county invited players from two neighbouring towns...

JAVA

Cricket County Selections (100 Marks)

A local cricket county invited players from two neighbouring towns Norwich, Ipswich to form a cricket team of 11 players to participate in an upcoming cricket tournament. After selection process, it has shortlisted 22 players from both towns together and tagged each player skill points between 5 to 10 (both numbers included, only whole numbers are considered) based on their performance. The county has also categorised players into pool of batsmen, bowlers, wicket keepers and all-rounders. A player can only belong to one pool. Now the county has asked its final selection committee to pick 11 players from all shortlisted players following the below rules:

A minimum of 3 and a maximum of 6 batsmen must be selected.

  • A minimum of 3 and a maximum of 6 bowlers must be selected.
  • A minimum of 1 and a maximum of 4 Wicket Keeper must be selected.
  • A minimum of 1 and a maximum of 4 All-rounders must be selected.
  • A maximum of 7 players can be selected from each town.
  • Skill points of selected players combined must not exceed 100 points.

Can you help the selection committee to understand in how many ways they can pick final 11?

Input Format

There will be 22 lines of input.

Each line of the input consists of skill of player, skill points of player and town of player space separately.

Constraints

5<= Skill Points <=10

Output Format

Print the total number of unique 11 member teams that can be formed with all the criteria mentioned in a separate line.

Sample TestCase 1

Input

Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Batsman 10 Ipswich
Bowler 10 Suffolk
Bowler 5 Suffolk
Bowler 5 Suffolk
WicketKeeper 10 Suffolk
AllRounder 10 Suffolk
Bowler 10 Suffolk
Bowler 10 Suffolk
Bowler 10 Suffolk
Bowler 10 Suffolk
Bowler 10 Suffolk
Bowler 10 Suffolk

Output

24486

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class CricketScore
{
   //implementing method creicket
   public static int cricket(int idx, int batsman, int bowler, int wk, int ar,
           int tw, int sum,int arr1[],int arr2[],int arr3[],int dp[][][][][][][])
   {
       //conditions to check no of batsmresult , bowlers , wicket_keeors
       if(batsman > 6 || bowler > 6 || wk > 4 || sum > 100 || tw > 7 || ar > 4)
       {
           return 0;
       }
       int tot = batsman + bowler + wk + ar;
       if(idx == 22)
       {
           if(tot != 11)
           {
               return 0;
           }
           if(batsman > 2 && bowler > 2 && wk > 0 && ar > 0 && tw >= 4)
           {
               return 1;
           }
           return 0;
       }
       int x1=idx,x2=batsman,x3=bowler,x4=wk,x5=ar,x6=tw,x7=sum;
       int result = dp[idx][batsman][bowler][wk][ar][tw][sum];
       if(result != -1)
       {
           dp[x1][x2][x3][x4][x5][x6][x7]=result;
           return result;
       }
       result = 0;
       dp[x1][x2][x3][x4][x5][x6][x7]=result;
       int variable_y=cricket(idx+1, batsman, bowler, wk, ar, tw, sum,arr1,arr2,arr3,dp);
       result+= variable_y;
       dp[x1][x2][x3][x4][x5][x6][x7]=result;
       if(arr1[idx] == 0) batsman++;
       if(arr1[idx] == 1) bowler++;
       if(arr1[idx] == 2) wk++;
       if(arr1[idx] == 3) ar++;
       sum+= arr2[idx];
       if(arr3[idx]!=0) tw++;
       dp[x1][x2][x3][x4][x5][x6][x7]=result;
       int variable_x=cricket(idx+1, batsman, bowler, wk, ar, tw, sum,arr1,arr2,arr3,dp);
       result+= variable_x;
       dp[x1][x2][x3][x4][x5][x6][x7]=result;
       return result;
   }
   public static void main(String[] args)
   {
       Scanner sc=new Scanner(System.in);
       int arr1[]=new int[22];//declaring arr1
       int arr2[]=new int[22];//declaring arr2
       int arr3[]=new int[22];//declaring arr3
       for(int i = 0; i < 22; i++)
       {
           String a;
           a=sc.next();
           if(a.equals("Batsman"))
           {
               arr1[i] = 0;
           }
           else if(a.equals("Bowler"))
           {
               arr1[i] = 1;
           }
           else if(a.equals("WicketKeeper"))
           {
               arr1[i] = 2;
           }
           else
           {
               arr1[i] = 3;
           }
           arr2[i]=sc.nextInt();
           String homeg;
           homeg=sc.nextLine();
           if(homeg.equals(" Ipswich"))
           {
               arr3[i] = 1;
           }
           else
           {
               arr3[i] = 0;
           }
       }
       int dp[][][][][][][]=new int[22][7][7][5][5][8][101];
       int x=-1;
       for (int i = 0; i < 22; i++){
           for (int j = 0; j < 7; j++) {
               for (int k = 0; k < 7; k++) {
                   for (int l = 0; l < 5; l++) {
                       for (int m = 0; m < 5; m++) {
                           for (int n = 0; n < 8; n++) {
                               for (int o = 0; o < 101; o++) {
           dp[i][j][k][l][m][n][o]=x;
       }}}}}}}
       //passsing vlues to method cricket
       int result = cricket(0, 0, 0, 0, 0, 0, 0,arr1,arr2,arr3,dp);
       //printing result
       System.out.println(result);
   }
}

Add a comment
Know the answer?
Add Answer to:
JAVA Cricket County Selections (100 Marks) A local cricket county invited players from two neighbouring towns...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third...

    I need that in Java CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third assignment will allow you to explore (by comparing and contrasting through construction and implementation) two different object-oncnted programman罨languages (C++ and Javal You will be creating tme scparate programs-onc written in C++ and on written in Java For this assignment, we are going to explore how we can use objects to build more expressive and cleaner programs. In honor of football season we are going...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT