当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7108:Command Sequence

题目描述
There is a robot that can move by receiving a sequence of commands.

There are four types of command in the command sequence:


  • $U$: robot moves one unit up.

  • $D$: robot moves one unit down.

  • $L$: robot moves one unit left.

  • $R$: robot moves one unit right.



Now, given a command sequence of length $n$. You need to find out how many substrings of the command sequence satisfy that if the robot execute the substring command, it can return to the starting position.

A substring is a contiguous sequence of characters within a string. For instance, "the best of" is a substring of "It was the best of times". For example, "Itwastimes" is a subsequence of "It was the best of times", but not a substring.
输入解释
This problem contains multiple test cases.

The first line contains an integer $t$ $(1 \leq t \leq 20)$ indicating the number of test cases.

For each test case, the first line contains one integer $n$ ($2 \leq n \leq 10 ^ 5$).

The second line contains a $UDLR$ string of length $n$.
输出解释
For each test case, output one line one integer indicating the answer.
输入样例
1
6
URLLDR
输出样例
2

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7108

最后修改于 2021-10-23T19:11:30+00:00 由爬虫自动更新

共提交 1

通过率 0.0%
时间上限 内存上限
2000/1000MS(Java/Others) 262144/262144K(Java/Others)