305018: CF954A. Diagonal Walking

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Diagonal Walking

题意翻译

$Mikhail$在一架飞机上行走。他可以往上走也可以往右走。 你得到了$Mikhail$的一系列动作。他认为这个序列太长了,他想使它尽可能短。 在给定的序列中,向上移动由字符$U$描述,右移动由字符$R$描述。 $Mikhail$可以用对角线移动,描述为字符$D$,替换任意一对连续的移动,$RU$或$UR$组合均可。 您的任务是打印替换后移动序列的最小可能长度。

题目描述

Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.

输入输出格式

输入格式


The first line of the input contains one integer $ n $ ( $ 1<=n<=100 $ ) — the length of the sequence. The second line contains the sequence consisting of $ n $ characters U and R.

输出格式


Print the minimum possible length of the sequence of moves after all replacements are done.

输入输出样例

输入样例 #1

5
RUURU

输出样例 #1

3

输入样例 #2

17
UUURRRRRUUURURUUU

输出样例 #2

13

说明

In the first test the shortened sequence of moves may be DUD (its length is $ 3 $ ). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is $ 13 $ ).

Input

题意翻译

$Mikhail$在一架飞机上行走。他可以往上走也可以往右走。 你得到了$Mikhail$的一系列动作。他认为这个序列太长了,他想使它尽可能短。 在给定的序列中,向上移动由字符$U$描述,右移动由字符$R$描述。 $Mikhail$可以用对角线移动,描述为字符$D$,替换任意一对连续的移动,$RU$或$UR$组合均可。 您的任务是打印替换后移动序列的最小可能长度。

加入题单

上一题 下一题 算法标签: