振兴中华
来源:互联网 发布:centos boot repair 编辑:程序博客网 时间:2024/06/18 03:54
小明参加了学校的趣味运动会,其中的一个项目是:跳格子。
地上画着一些格子,每个格子里写一个字,如下所示:
从 我 做 起 振
我 做 起 振 兴
做 起 振 兴 中
起 振 兴 中 华
比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。
要求跳过的路线刚好构成“从我做起振兴中华”这句话。
请你帮助小明算一算他一共有多少种可能的跳跃路线呢?
public class ZhenXing {private static char [] [] a={{'从','我','做','起','振'}, {'我','做','起','振','兴'}, {'做','起','振','兴','中'}, {'起','振','兴','中','华'}};private static int count; //计数器public static void main(String[] args) { count=0; char [] b=new char[8]; judge(0, 0, 0, b); System.out.println(count);}/* 模拟小明跳跃格子的递归方法 * step 跳格子经过的步数,范围是0-7 * x 向下跳的位置,范围是0-3 * y 向右跳的位置,范围是0-4 * b 暂存跳过路线的一维数组 */private static void judge(int step,int x,int y,char [] b){if(x>3){return;}if(y>4){return;}if(step>7){return;}b[step]=a[x][y]; //记录跳过的字if(step==7){ //刚好走到第八个位置if(check(b)){count++;}return;}//有两种情况,向下跳或者向右跳judge(step+1, x+1, y, b); judge(step+1, x, y+1, b); }//检查数组内容是“从我做起振兴中华”private static boolean check(char[] b){ if(String.valueOf(b).equals("从我做起振兴中华")){ return true; }else{ return false; }}}
阅读全文
0 0
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- centos7.2 1511 安装CGAL4-7
- 线程的抢占式和协作式详解
- 大数据学习3——分布式文件系统HDFS
- 快速上手MQ之activeMQ(2)--spring整合
- 二维数组计算
- 振兴中华
- 小白笔记---------------------------------leetcode(101. Symmetric Tree )
- struts2报错The Struts dispatcher cannot be found
- 卷积神经网络Quiz1
- Storage Clean小节
- jquery easyui如何通过idField获取某行?
- 国内一线互联网技术团队帮你进阶,助你成长
- 第八篇
- Elasticsearch如何设置mapping