-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathEtaKappaNu.java
76 lines (76 loc) · 1.51 KB
/
EtaKappaNu.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Scanner;
import java.util.Arrays;
class Solution
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
while(true)
{
int n=Integer.parseInt(s.nextLine());
if(n==0)
break;
String s1[]=s.nextLine().split(" ");
String s2[]=s.nextLine().split(" ");
int M[][]=new int[n+1][n+1];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(s1[i-1].equals(s2[j-1]))
{
M[i][j]=M[i-1][j-1]+2*getVal(s1[i-1]);
int ti=i-1;
int max=0;
for(int tj=0;tj<j;tj++)
{
if(M[ti][tj]>max)
max=M[ti][tj];
}
M[i][j]=max+2*getVal(s1[i-1]);
}
else if(s1[i-1].equals("R"))
{
int ti=i-1;
int max=0;
for(int tj=0;tj<j;tj++)
{
if(M[ti][tj]>max)
max=M[ti][tj];
}
M[i][j]=max+2*getVal(s2[j-1]);
}
else if(s2[j-1].equals("R"))
{
int tj=j-1;
int max=0;
for(int ti=0;ti<i;ti++)
{
if(M[ti][tj]>max)
max=M[ti][tj];
}
M[i][j]=max+2*getVal(s1[i-1]);
}
else
M[i][j]=Math.max(M[i-1][j],M[i][j-1]);
}
}
// for(int i=0;i<=n;i++)
// System.out.println(Arrays.toString(M[i]));
System.out.println(M[n][n]);
}
}
static int getVal(String s)
{
if(s.equals("R"))
return 50;
else if(s.equals("A"))
return 20;
else if(s.equals("J")||s.equals("Q")||s.equals("K"))
return 15;
else if(s.equals("T"))
return 10;
else
return Integer.parseInt(s);
}
}