B. Fix You

http://codeforces.com/contest/1391/problem/B

题面:

Consider a conveyor belt represented using a grid consisting of nnn rows and mmm columns. The cell in the iii-th row from the top and the jjj-th column from the left is labelled (i,j)(i,j)(i,j).

Every cell, except (n,m)(n,m)(n,m), has a direction R (Right) or D (Down) assigned to it. If the cell (i,j)(i,j)(i,j) is assigned direction R, any luggage kept on that will move to the cell (i,j+1)(i,j+1)(i,j+1). Similarly, if the cell (i,j)(i,j)(i,j) is assigned direction D, any luggage kept on that will move to the cell (i+1,j)(i+1,j)(i+1,j). If at any moment, the luggage moves out of the grid, it is considered to be lost.

There is a counter at the cell (n,m)(n,m)(n,m) from where all luggage is picked. A conveyor belt is called functional if and only if any luggage reaches the counter regardless of which cell it is placed in initially. More formally, for every cell (i,j)(i,j)(i,j), any luggage placed in this cell should eventually end up in the cell (n,m)(n,m)(n,m).

This may not hold initially; you are, however, allowed to change the directions of some cells to make the conveyor belt functional. Please determine the minimum amount of cells you have to change.

Please note that it is always possible to make any conveyor belt functional by changing the directions of some set of cells.

Input

Each test contains multiple test cases. The first line contains the number of test cases ttt (1≤t≤101 \le t \le 101≤t≤10). Description of the test cases follows.

The first line of each test case contains two integers n,mn, mn,m (1≤n≤1001 \le n \le 1001≤n≤100, 1≤m≤1001 \le m \le 1001≤m≤100) — the number of rows and columns, respectively.

The following nnn lines each contain mmm characters. The jjj-th character in the iii-th line, ai,ja_{i,j}ai,j​ is the initial direction of the cell (i,j)(i, j)(i,j). Please note that an,m=a_{n,m}=an,m​= C.

Output

For each case, output in a new line the minimum number of cells that you have to change to make the conveyor belt functional.

Example

input

4
3 3
RRD
DDR
RRC
1 4
DDDC
6 9
RDDDDDRRR
RRDDRRDDD
RRDRDRRDR
DDDDRDDRR
DRRDRDDDR
DDRDRRDDC
1 1
C

output

1
3
9
0

Note

In the first case, just changing the direction of (2,3)(2,3)(2,3) to D is enough.

You can verify that the resulting belt is functional. For example, if we place any luggage at (2,2)(2,2)(2,2), it first moves to (3,2)(3,2)(3,2) and then to (3,3)(3,3)(3,3).

In the second case, we have no option but to change the first 333 cells from D to R making the grid equal to RRRC.

翻译:

考虑一个传输带conveyor belt 被表示为represented 使用一个表格组成consisting 由 n 行rows 和 m列columns 。顶部第 i 行和左侧第 j 列 的大院个被标记成 (i,j)(i,j)(i,j).

每一个单元格,除了 (n,m)(n,m)(n,m) ,都有方向 direction R和D被分配 assigned 。如果单元格 (i,j)(i,j)(i,j) 被分配为 方向R,任何行李 luggage 将继续移动向单元 $ (i,j+1) $ 。同样,如果单元格被分配为方向D,任何行李将继续移动到(i+1,j)(i+1,j)(i+1,j)。如果任何时候,行李移动出格子,他将被视为丢失。

这里有一个柜台counter 在(n,m)(n,m)(n,m)的单元格从这里所有行李都被取走picked。当且仅当if and only if 任何行李到达柜台 无论regardless 是从哪个单元格被放置最初,传送带都被叫做功能性functional 传送带。更正式formally的说,对于每一个单元格(i,j)(i,j)(i,j),任何行李被放置在这个单元格应该最终结束在 (n,m)(n,m)(n,m).

最初这个可能不成立,但是,你可以,允许一些改变 方向对于某些单元格 使得传送带工作。请确定最小化数值的单元格 你改变的。

请注意,他总是可以使得所有传送带工作 通过改变方向 对于某些单元格。

题意:

给你一个表,每个单元格上有方向R或者D,求每一个点都可以到最后 (n,m)(n,m)(n,m)点,更改的最小值。

题解:

因为每个点都是 R D 那么除了最右边和最下面的,每个点都可以跑到最右边或者最下面,所以只要将这两个边变成都会走向 最后一个点就行了。即统计最右边有几个R 最下面有几个D,cntcntcnt 就是最小修改值。

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAX = 105;char s[MAX][MAX];int main()
{int T;scanf("%d", &T);while (T--){int n, m;int ans = 0;scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++)scanf("%s", s[i] + 1);for (int i = 1; i < n; i++){if (s[i][m] == 'R')ans++;}for (int i = 1; i < m; i++){if (s[n][i] == 'D')ans++;}printf("%d\n", ans);}return 0;
}

1391 B(a).Fix You(规律+构造)相关推荐

  1. Ural 2037. Richness of binary words 打表找规律 构造

    2037. Richness of binary words 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2037 Descripti ...

  2. 【CodeForces - 764D】Timofey and rectangles (四色定理 + 找规律 + 构造)

    题干: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane ...

  3. 拼多多 2020校招 多多的排列函数(找规律 构造)

    数列 {An} 为N的一种排列. 例如N=3,可能的排列共6种: 1 2 3 4 5 6 1, 2, 3 1, 3, 2 2, 1, 3 2, 3, 1 3, 1, 2 3, 2, 1 定义函数F: ...

  4. 【qduoj】奇数阶幻方 (构造)

    题干: C语言_魔方阵 描述 魔方阵是一个古老的智力问题,它要求在一个m×m的矩阵中填入1-m2的数字(m为奇数),使得每一行.每一列.每条对角线的累加和都相等,如下为5阶魔方阵示例. 15 8 1 ...

  5. 梅宏院士:如何构造人工群体智能?| 智源大会特邀报告回顾

    来源:智源社区 导读:在自然界当中,群体智能广泛存在,诸如蜂群.蚁群以及鱼群的聚集.而从宏观上说,人类社会的不断发展和演化也是一种群体智能现象,绝大多数文明成果都是人类个体在长期群体化.社会化的生产生 ...

  6. 梅宏院士:如何构造人工群体智能

    本文内容由数据派THU 整理自梅宏院士在清华软件论坛上所做的专题报告 一.群体智能研究现状 群体智能是科学家长期关注和研究的一种自然现象.在很多低等社会性生物群体中可以观察到,群体中的单一个体不具有智 ...

  7. 【Python】数据提取xpath和lxml模块(糗事百科的爬虫)

    程序中用到的一些零碎知识点: 一.列表推导式:帮助我们快速生成一堆数据的列表 1.format:字符串格式化的一种方式 >>> ["10月{}日".format( ...

  8. 第15讲:Selenium 爬取实战

    在上一课时我们学习了 Selenium 的基本用法,本课时我们就来结合一个实际的案例来体会一下 Selenium 的适用场景以及使用方法. 1.准备工作 在本课时开始之前,请确保已经做好了如下准备工作 ...

  9. 2013_chengdu_online

    4728 A Game in the Hospital 4729 An Easy Problem for Elfness 4730 We Love MOE Girls 签到题目 4731 Minimu ...

最新文章

  1. java和C++ C比较
  2. Linux用户环境变量
  3. CSS------当内容超出div宽度后自动换行和限制文字不超出div宽度和高度
  4. 关于session共享
  5. 神经网络 | 受限波尔兹曼机(附源代码)
  6. Web前端开发学习资料分享
  7. 曾优雅击退史上最凶狠的DDoS攻击,AliGuard的高性能从何而来?
  8. linux下getrlimit与sysconf函数
  9. (软件工程复习核心重点)第十章面向对象设计-第四节:设计人机交互子系统和设计任务管理子系统
  10. 线程控制、如何给面试官描述线程不安全的情况?模拟黄牛抢票展现不安全的情况及解决方式、互斥锁加锁解锁
  11. JQuery DataTable的配置项及事件
  12. GA遗传算法(Genetic Algorithm)
  13. Unity API学习笔记(2)-GameObject的3种Message消息方法
  14. 服务器sel信息是什么意思,英特尔?服务器主板 — 如何解压和读取的服务器事件日志(SEL)...
  15. C语言词法分析程序的设计与实现
  16. 洛谷 P5322 [BJOI2019]排兵布阵
  17. 初步认识C语言中的选择和循环语句
  18. u-boot启动流程分析
  19. Android 10 设置kernel log level
  20. IOS原生生成二维码

热门文章

  1. 科汛kesioncms系统参数配置”中的网址会自动加上:443如何解决
  2. Django实战项目--爱鲜蜂day1
  3. 基于docker部署glusterfs
  4. 如何用木板做桥_用木板搭桥小游戏-抖音用木板搭桥1.6 安卓版-东坡下载
  5. python爬虫-彻底解决网页乱码
  6. 互联网金融之数据库表字段词根表
  7. ac自动机 匹配最长前缀_AC自动机算法
  8. LDA主题模型困惑度计算
  9. 4 数字加密 (15分)——一维数组
  10. Apache Open Sourse List 项目列表