博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多校9 1007 Travelling Salesman Problem
阅读量:6546 次
发布时间:2019-06-24

本文共 2026 字,大约阅读时间需要 6 分钟。

Travelling Salesman Problem

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 829    Accepted Submission(s): 182
Special Judge

Problem Description
Teacher Mai is in a maze with 
n rows and m columns. There is a non-negative number in each cell. Teacher Mai wants to walk from the top left corner (1,1) to the bottom right corner (n,m). He can choose one direction and walk to this adjacent cell. However, he can't go out of the maze, and he can't visit a cell more than once.
Teacher Mai wants to maximize the sum of numbers in his path. And you need to print this path.
 

 

Input
There are multiple test cases.
For each test case, the first line contains two numbers 
n,m(1n,m100,nm2).
In following n lines, each line contains m numbers. The j-th number in the i-th line means the number in the cell (i,j). Every number in the cell is not more than 104.
 

 

Output
For each test case, in the first line, you should print the maximum sum.
In the next line you should print a string consisting of "L","R","U" and "D", which represents the path you find. If you are in the cell 
(x,y), "L" means you walk to cell (x,y1), "R" means you walk to cell (x,y+1), "U" means you walk to cell (x1,y), "D" means you walk to cell (x+1,y).
 

 

Sample Input
3 3 2 3 3 3 3 3 3 3 2
 

 

Sample Output
25 RRDLLDRR
1 #include 
2 #include
3 int main() 4 { 5 int n,m; 6 int a[106][106],s,x,y; 7 int i,j,k; 8 while(scanf("%d %d",&n,&m)!=EOF) 9 { 10 s=0; 11 int mi; 12 for(i=1;i<=n;i++) 13 { 14 for(j=1;j<=m;j++) 15 { 16 scanf("%d",&a[i][j]); 17 s=s+a[i][j]; 18 } 19 } 20 if(n%2==1) 21 { 22 printf("%d\n",s); 23 for(i=1;i<=n;i++) 24 { 25 if(i%2==1) 26 { 27 for(j=1;j
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771398.html

你可能感兴趣的文章
POJ-2253 Frogger 最短路
查看>>
devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)...
查看>>
idea教程视频以及常用插件整理
查看>>
JdbcUtils 小工具
查看>>
记录console的使用
查看>>
酷狗音乐下载
查看>>
signal.h(c标准库)
查看>>
Pascal 语言中二维数组:矩阵问题
查看>>
fileUpload(草稿)
查看>>
CF494C Helping People
查看>>
【转载】Relevant literature
查看>>
Android常见的几种RuntimeException(转)
查看>>
Linux学习总结(11)——Linux文件查找
查看>>
Java基础学习总结(44)——10个Java 8 Lambda表达式经典示例
查看>>
Beetl学习总结(2)——基本用法
查看>>
Java基础学习总结(78)——Java main方法深入研究学习
查看>>
网页的缓存Cache与控制
查看>>
对象的比较与排序(七):对泛型列表进行排序和搜索:Comparison<T>和Predicate<T>的应用...
查看>>
SQL重复记录查询的几种方法
查看>>
[网络流24题] 最长递增子序列 (最多不相交路径---网络最大流)
查看>>