I can run a small amount of a.b, but when the number is too much, time out. Ask the Great God
Robot Tower
Planet X's robot performance cheerleaders have two kinds of costumes, A and B.
Their performance this time is the robot tower.
Similar:
A
b b
A B A
A A b b
b b b A b
A B a b b a
The team tower rules are:
A can only stand on the shoulders of a AA or BB.
B can only stand on the shoulders of AB or BA.
Your task is to help the cheerleaders figure out how many kinds of towers can be formed in the given number of a and B.
Enter a line of two integers M and N, separated by spaces (0<m,n<500), representing the number of a and b respectively, to ensure the rationality of the number.
Requires output an integer representing the number of patterns that can be generated.
For example:
User input:
1 2
The program should output:
3
Again for example:
User input:
3 3
The program should output:
4
Think of the a\b as 1.2. The position of the Triangle Tower is from 0. The lower left position of each position is exactly the same as the number of rows in the lower right position.
Import Java.util.Scanner;
Public class robot Tower {public
static int n,m,sum,a[],n1,m1;
public static void Main (string[] args) {
Scanner s=new Scanner (system.in);
N=s.nextint ();
M=s.nextint ();
A=new Int[n+m];
A (a,0);
SYSTEM.OUT.PRINTLN (sum);
public static void A (int c[],int k) {
if (k==c.length) {
if (n1==n&&m1==m) {
if (judge (c)
) sum++
}
} else{for
(int i=1;i<=2;i++) {
if (i==1) {
c[k]=i;
n1++;
A (c,k+1);
n1--;
}
else if (i==2) {
c[k]=i;
m1++;
A (c,k+1);
m1--
}
}}} public static Boolean judge (int a[]) {
int i=0;
for (int j=1;i+j<a.length;j++) {//=
for (int k=0;k<j;k++) {//per row number of
if (a[i]==1) {
if (a[i+j) starting from the first line ]!=a[i+j+1]) {return
false;
}
}
if (a[i]==2) {
if (a[i+j]==a[i+j+1]) {return
false;
}
}}
i++
}
}
return true;
}