zoj2412Farm Irrigation(深搜)
来源:互联网 发布:java 获取项目路径 编辑:程序博客网 时间:2024/05/29 08:33
Time Limit: 1 Second Memory Limit: 32768 KB
Benny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are placed in these squares. Different square has a different type of pipe. There are 11 types of pipes, which is marked from A to K, as Figure 1 shows.
Figure 1
Benny has a map of his farm, which is an array of marks denoting the distribution of water pipes over the whole farm. For example, if he has a map
ADCFJKIHE
then the water pipes are distributed like
Figure 2
Several wellsprings are found in the center of some squares, so water can flow along the pipes from one square to another. If water flow crosses one square, the whole farm land in this square is irrigated and will have a good harvest in autumn.
Now Benny wants to know at least how many wellsprings should be found to have the whole farm land irrigated. Can you help him?
Note: In the above example, at least 3 wellsprings are needed, as those red points in Figure 2 show.
Input
There are several test cases! In each test case, the first line contains 2 integers M and N, then M lines follow. In each of these lines, there are N characters, in the range of 'A' to 'K', denoting the type of water pipe over the corresponding square. A negative M or N denotes the end of input, else you can assume 1 <= M, N <= 50.
Output
For each test case, output in one line the least number of wellsprings needed.
Sample Input
2 2DKHF3 3ADCFJKIHE-1 -1
Sample Output
23
- zoj2412Farm Irrigation(深搜)
- ZOJ2412Farm Irrigation
- HDU 1198 Farm Irrigation(深搜)
- hdu 1198 Farm Irrigation(深搜dfs || 并查集)
- Farm Irrigation
- Farm Irrigation
- Farm Irrigation
- Farm Irrigation
- hdu1198Farm Irrigation
- hdu1198Farm Irrigation
- Farm Irrigation
- Farm Irrigation
- Farm Irrigation
- ZOJ 2412 Farm Irrigation
- zoj 2412 Farm Irrigation
- HDU 1198 Farm Irrigation
- ZOJ 2412 Farm Irrigation
- 1198 Farm Irrigation
- asp.net UpdatePanel的简单用法
- http://del.cnblogs.com/ 万一的博客
- delphi copyrect实现的几个图片的转换效果
- 主服务器如何定时获取分服务器的数据?
- web服务接口实例
- zoj2412Farm Irrigation(深搜)
- Spring中使用annotation注入
- 【设计模式】之单例模式(and多例模式)
- sql游标实例
- hdoj1014Uniform Generator模拟题
- 批量导入数据
- 免费文献搜索网站
- Android SDK工具:使用layoutopt进行布局优化
- oracle正常使用必须开启的服务