招银第三题,自动机转换
初始化(以**结尾有多少个)
无C:A 1 B 1 BB 0
一个C:A 0 B 0 BB 0 C 1
状态转换(下面数字分别对应上述1-7种状态)
状态转换(下面数字分别对应上述1-7种状态)
耐心点推出来,写代码就是分分钟的事情
package practice; import java.util.Scanner; public class Main { public static void main(String[] args) { long a = 1; long b = 1; long c = 0; long d = 0; long e = 0; long f = 0; long g = 1; Scanner sc = new Scanner(System.in); int n = sc.nextInt() - 1; while (n-- > 0) { long tempa = a; long tempb = b; long tempc = c; long tempd = d; long tempe = e; long tempf = f; long tempg = g; a = tempa + tempb + tempc; b = tempa; c = tempb; d = tempd + tempe + tempf + tempg; e = tempd + tempg; f = tempe; g = tempa + tempb + tempc; } System.out.println(a + b + c + d + e + f + g); } }