{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "9fc1fa0c4a6941a5af8c58f8a17072b6",
  "keywords": "图算法,算法高阶,图的表示,基本的图算法",
  "title": "最优路线",
  "desc": [
    {
      "content": "\n题目描述\n探险队要穿越泥潭，必须选择可踩踏的落脚点。可是泥潭面积很大，落脚点又实在少得可怜，一不小心就会深陷泥潭而无法脱身。侦查员费尽周折才从老乡手里弄到了一份地图，图中标出了落脚点的位置，而且令人震惊的是：泥潭只有一条穿越路线，且对于 n×m 的地图，路线长度为 n+m-1！请编程为探险队找出穿越路线。\n输入描述\n两个整数 n 和 m，表示泥潭的长和宽。下面 n 行 m 列表示地形（0 表示泥潭，1 表示落脚点）\n输出描述\n用坐标表示穿越路线，坐标之间用 > 分隔\n样例输入\n6 9\n1 1 1 0 0 0 0 0 0\n0 0 1 1 1 0 0 0 0\n0 0 0 0 1 0 0 0 0\n0 0 0 0 1 1 0 0 0\n0 0 0 0 0 1 1 1 1\n0 0 0 0 0 0 0 0 1\n样例输出\n(1,1)>(1,2)>(1,3)>(2,3)>(2,4)>(2,5)>(3,5)>(4,5)>(4,6)>(5,6)>(5,7)>(5,8)>(5,9)>(6,9)",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <string.h>\nconst int N=101;\nint map[N][N];\nint n,m;\nstruct point{\n\tint l,r;\n}node[N];\nint ans;\nvoid DFS(int x,int y)\n{\n\tif(x==n&&y==m)\n\t{\n\t\tfor(int i=1;i<ans;i++)\n\t\t\tprintf(\"(%d,%d)>\", node[i].l, node[i].r);\n\t\tprintf(\"(%d,%d)\\n\", x, y);\n\t}\n\telse{\n\t\tif(map[x][y]==1&&x<=n&&y<=m)\n\t\t{\n\t\t\tnode[ans].l=x;\n\t\t\tnode[ans].r=y;\n\t\t\tans++;\n\t\t\tDFS(x+1,y);\n\t\t\tDFS(x,y+1);\n\t\t}\n\t}\n}\nint main()\n{\n\twhile(scanf(\"%d%d\", &n, &m) != EOF)\n\t{\n\t\tans=1;\n\t\tmemset(map,0,sizeof(map));\n\t\tfor(int i=1;i<=n;i++)\n\t\t\tfor(int j=1;j<=m;j++)\n\t\t\t\tscanf(\"%d\", &map[i][j]);\n\t\tDFS(1,1);\t\n\t}\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-ef701b1245294488a29c1d7609ccc901",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470149"
}