您的位置:首页 > 其它

振兴中华

2017-02-09 02:01 169 查看
标题: 振兴中华

小明参加了学校的趣味运动会,其中的一个项目是:跳格子。

地上画着一些格子,每个格子里写一个字,如下所示:(也可参见p1.jpg)

从我做起振

我做起振兴

做起振兴中

起振兴中华

比赛时,先站在左上角的写着“从”字的格子里,可以横向或纵向跳到相邻的格子里,但不能跳到对角的格子或其它位置。一直要跳到“华”字结束。

要求跳过的路线刚好构成“从我做起振兴中华”这句话。

请你帮助小明算一算他一共有多少种可能的跳跃路线呢?

答案是一个整数,请通过浏览器直接提交该数字。

注意:不要提交解答过程,或其它辅助说明类的内容。

一共有

(8分)种可能的跳跃路线

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const string a[4][8] = {{"从","我","做","起","振"},
{"我","做","起","振","兴"},
{"做","起","振","兴","中"},
{"起","振","兴","中","华"}};
int count;
string val[8];
int check(string val[]){
if(val[0] == "从" && val[1] == "我" && val[2] == "做" && val[3] == "起" && val[4] == "振" && val[5] == "兴" && val[6] == "中" && val[7] == "华" )
return 1;
else return 0;
}
// "从我做起振兴中华"
void dfs(int step, int x, int y){
if(x > 3){
return;
}
if(y > 4){
return;
}
if(step > 7){
return;
}
val[step] = a[x][y];
if(step == 7){
if(check(val)){
count++;
}
return;
}
dfs(step+1,x+1,y);
dfs(step+1,x,y+1);
}
int main(){
count = 0;

dfs(0,0,0);
cout << count << endl;
return 0;
}


count == 35;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: