21897_Touris

2022-5-16 18:20| 发布者: Hocassian| 查看: 26| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505940262900-Problem List-采集的数据-后羿采集器.html

Pro.ID

21897

Title

Tourist

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21897

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    A lazy tourist wants to visit as many interesting locations in a city as possible without going one step further than necessary. Starting from his hotel, located in the north-west corner of city, he intends to take a walk to the south-east corner of the city and then walk back. When walking to the south-east corner, he will only walk east or south, and when walking back to the north-west corner, he will only walk north or west. After studying the city map he realizes that the task is not so simple because some areas are blocked. Therefore he has kindly asked you to write a program to solve his problem.

    Given the city map (a 2D grid) where the interesting locations and blocked areas are marked, determine the maximum number of interesting locations he can visit. Locations visited twice are only counted once.

    输入

    The first line in the input contains the number of test cases (at most 20). Then follow the cases. Each case starts with a line containing two integers, W and H ( 2 <= W, H <= 100 ), the width and the height of the city map. Then follow H lines, each containing a string with W characters with the following meaning:

    • '.' Walkable area
    • '*' Interesting location (also walkable area)
    • '#' Blocked area
    You may assume that the upper-left corner (start and end point) and lower-right corner (turning point) are walkable, and that a walkable path of length H + W - 2 exists between them.

    输出

    Description

    A lazy tourist wants to visit as many interesting locations in a city as possible without going one step further than necessary. Starting from his hotel, located in the north-west corner of city, he intends to take a walk to the south-east corner of the city and then walk back. When walking to the south-east corner, he will only walk east or south, and when walking back to the north-west corner, he will only walk north or west. After studying the city map he realizes that the task is not so simple because some areas are blocked. Therefore he has kindly asked you to write a program to solve his problem.

    Given the city map (a 2D grid) where the interesting locations and blocked areas are marked, determine the maximum number of interesting locations he can visit. Locations visited twice are only counted once.

    Input

    The first line in the input contains the number of test cases (at most 20). Then follow the cases. Each case starts with a line containing two integers, W and H ( 2 <= W, H <= 100 ), the width and the height of the city map. Then follow H lines, each containing a string with W characters with the following meaning:

    • '.' Walkable area
    • '*' Interesting location (also walkable area)
    • '#' Blocked area
    You may assume that the upper-left corner (start and end point) and lower-right corner (turning point) are walkable, and that a walkable path of length H + W - 2 exists between them.
    Output
    For each test case, output a line containing a single integer: the maximum number of interesting locations the lazy tourist can visit.
    Sample Input
    2
    9 7
    *........
    .....**#.
    ..**...#*
    ..####*#.
    .*.#*.*#.
    ...#**...
    *........
    5 5
    .*.*.
    *###.
    *.*.*
    .###*
    .*.*.
    Sample Output
    7
    8
    Source

    样例输入

    2
    9 7
    *........
    .....**#.
    ..**...#*
    ..####*#.
    .*.#*.*#.
    ...#**...
    *........
    5 5
    .*.*.
    *###.
    *.*.*
    .###*
    .*.*.

    样例输出

    7
    8

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部