In: Statistics and Probability
JAVA JAVA JAVA JAVA JAVA JAVA
Cricket County Selections
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.
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
Java code:-
import java.util.*;
public class CandidateCode
{
public static int recurse(int idx, int batsman, int bowler, int wk,
int ar, int towner, int sum,int trade[],int skiint[],int town[],int
dp[][][][][][][])
{
if(batsman > 6 || bowler > 6 || wk > 4 || sum > 100 ||
towner > 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 && towner >= 4)
{
return 1;
}
return 0;
}
int x1=idx,x2=batsman,x3=bowler,x4=wk,x5=ar,x6=towner,x7=sum;
int ans = dp[idx][batsman][bowler][wk][ar][towner][sum];
if(ans != -1)
{
dp[x1][x2][x3][x4][x5][x6][x7]=ans;
return ans;
}
ans = 0;
dp[x1][x2][x3][x4][x5][x6][x7]=ans;
int variable_y=recurse(idx+1, batsman, bowler, wk, ar, towner,
sum,trade,skiint,town,dp);
ans+= variable_y;
dp[x1][x2][x3][x4][x5][x6][x7]=ans;
if(trade[idx] == 0) batsman++;
if(trade[idx] == 1) bowler++;
if(trade[idx] == 2) wk++;
if(trade[idx] == 3) ar++;
sum+= skiint[idx];
if(town[idx]!=0) towner++;
dp[x1][x2][x3][x4][x5][x6][x7]=ans;
int variable_x=recurse(idx+1, batsman, bowler, wk, ar, towner,
sum,trade,skiint,town,dp);
ans+= variable_x;
dp[x1][x2][x3][x4][x5][x6][x7]=ans;
return ans;
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int trade[]=new int[22];
int skiint[]=new int[22];
int town[]=new int[22];
for(int i = 0; i < 22; i++) {
String a;
a=sc.next();
if(a.equals("Batsman"))
{
trade[i] = 0;
}
else if(a.equals("Bowler"))
{
trade[i] = 1;
}
else if(a.equals("WicketKeeper"))
{
trade[i] = 2;
}
else
{
trade[i] = 3;
}
skiint[i]=sc.nextInt();
String homeg;
homeg=sc.nextLine();
if(homeg.equals(" Ipswich"))
{
town[i] = 1;
}
else
{
town[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;
}}}}}}}
int ans = recurse(0, 0, 0, 0, 0, 0, 0,trade,skiint,town,dp);
System.out.println(ans);
}
}