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 (,) 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(≤n,m≤,n∗m≥).

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 .
 
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,y−), "R" means you walk to cell (x,y+), "U" means you walk to cell (x−,y), "D" means you walk to cell (x+,y).

 
Sample Input

  
 
Sample Output
RRDLLDRR
 
Author
xudyh
 
Source
 
真是个鸟题,一开始把情况都考虑了,交上去直接WA了,后来意识到是n、m同为偶数有错。  其实只要找找规律就可以得出找的最小值的横纵坐标的和要为奇数,不过这个的顺序也是很难写啊。。。。。。
 
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int mp[][];
int x,y;
int minn;
void get()
{
x = ; y = ;
for (int i = ; i <= n;i++)
for (int j = ; j <= m; j++)
if (((i + j) & ) && mp[x][y] > mp[i][j]) x = i, y = j;
}
int main()
{
while(scanf("%d%d",&n,&m)==)
{
int sum=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
scanf("%d",&mp[i][j]);
sum+=mp[i][j];
}
}
if((n&))
{ printf("%d\n",sum);
if(n==)
{
for(int i=;i<m;i++)
printf("R");
printf("\n");
continue;
}
for(int i=;i<m;i++)
printf("R");
printf("D");
for(int i=;i<=n;i++)
{
if(i%==)
{
for(int j=;j<m;j++)
printf("L");
printf("D");
}
else
{
if(i!=n)
{
for(int i=;i<m;i++)
printf("R");
printf("D");
}
else
{
for(int i=;i<m;i++)
printf("R");
}
}
}
printf("\n"); }
else if((m%))
{
printf("%d\n",sum);
if(m==)
{
for(int i=;i<n;i++)
printf("D");
printf("\n");
continue;
}
for(int i=;i<n;i++)
printf("D");
printf("R");
for(int i=;i<=m;i++)
{
if(i%==)
{
for(int j=;j<n;j++)
printf("U");
printf("R");
}
else
{
if(i!=m)
{
for(int j=;j<n;j++)
printf("D");
printf("R");
}
else
{
for(int j=;j<n;j++)
printf("D");
}
}
}
printf("\n");
}
else if((m%)== && (n%)==)
{
get();
printf("%d\n", sum - mp[x][y]);
for (int i = ; i <= n; i += )
{
if (x == i || x == i + )
{
for (int j = ; j < y; j++)
{
if (j & ) printf("D"); else printf("U");
printf("R");
}
if (y < m) printf("R");
for (int j = y + ; j <= m; j++)
{
if (j & ) printf("U"); else printf("D");
if (j < m) printf("R");
}
if (i < n - ) printf("D");
}
else if (i < x)
{
for (int j = ; j < m; j++) printf("R");
printf("D");
for (int j = ; j < m; j++) printf("L");
printf("D");
}
else
{
for (int j = ; j < m; j++) printf("L");
printf("D");
for (int j = ; j < m; j++) printf("R");
if (i < n - ) printf("D");
}
}
printf("\n");
} }
return ;
}
 

hdu 5402 Travelling Salesman Problem(大模拟)的更多相关文章

  1. HDU 5402 Travelling Salesman Problem (模拟 有规律)(左上角到右下角路径权值最大,输出路径)

    Travelling Salesman Problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (J ...

  2. 构造 - HDU 5402 Travelling Salesman Problem

    Travelling Salesman Problem Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5402 Mean: 现有一 ...

  3. HDU 5402 Travelling Salesman Problem (构造)(好题)

    大致题意:n*m的非负数矩阵,从(1,1) 仅仅能向四面走,一直走到(n,m)为终点.路径的权就是数的和.输出一条权值最大的路径方案 思路:因为这是非负数,要是有负数就是神题了,要是n,m中有一个是奇 ...

  4. HDU 5402 Travelling Salesman Problem(多校9 模拟)

    题目链接:pid=5402">http://acm.hdu.edu.cn/showproblem.php?pid=5402 题意:给出一个n×m的矩阵,位置(i.j)有一个非负权值. ...

  5. HDU 5402 Travelling Salesman Problem(棋盘染色 构造 多校啊)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5402 Problem Description Teacher Mai is in a maze wit ...

  6. HDU 5402 : Travelling Salesman Problem

    题目大意:n*m的格子,从左上角走到右下角,每个格子只能走一遍,每个格子上有一个非负数,要让途径的数字和最大,最后要输出路径 思路:显然茹果n,m有一个是奇数的话所有格子的数字都能被我吃到,如果都是偶 ...

  7. hdu 5402 Travelling Salesman Problem (技巧,未写完)

    题意:给一个n*m的矩阵,每个格子中有一个数字,每个格子仅可以走一次,问从(1,1)走到(n,m) 的路径点权之和. 思路: 想了挺久,就是有个问题不能短时间证明,所以不敢下手. 显然只要n和m其中一 ...

  8. HDOJ 5402 Travelling Salesman Problem 模拟

    行数或列数为奇数就能够所有走完. 行数和列数都是偶数,能够选择空出一个(x+y)为奇数的点. 假设要空出一个(x+y)为偶数的点,则必须空出其它(x+y)为奇数的点 Travelling Salesm ...

  9. HDU 5402(Travelling Salesman Problem-构造矩阵对角最长不相交路径)

    Travelling Salesman Problem Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (J ...

随机推荐

  1. 高性能 Socket 组件 HP-Socket v3.2.1-RC4 公布

    HP-Socket 是一套通用的高性能 TCP/UDP Socket 组件,包括服务端组件.client组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C+ ...

  2. C#winform检测电脑安装的.netframework版本和是否安装了某软件

    代码如下: //C#获取已安装 .NET Framework 版本 private static string[] GetDotNetVersions() { DirectoryInfo[] dire ...

  3. (转)使用 .NET 的 RNGCryptoServiceProvider 生成随机数

    1. [代码]一个简单的方法,但不够可靠     跳至 [1] [2] [全屏预览] ? 1 2 3 4 5 6 7 8 9 10 11 static void Main(string[] args) ...

  4. MVC第一节 配置

    1.View中的页面设置为起始页后导致404找不到文件. 解决方案:右键属性,把特定页置为空. 2.新建的MVC项目会把系统默认的浏览器作为浏览方式,如果想要改变的话.可以在项目中新建一个webFor ...

  5. MongoVUE查询备忘

    用了一段时间的MongoVUE,把一些在MongoVUE中常用的查询记录一下,以便查阅.1.and查询    查询date等于2016-01-08,并且page_url等于shouye.html   ...

  6. partial修饰符,可以让同类命名空间下出现重名

    public partial class Person { } public partial class Person { } partial修饰符,可以让同类命名空间下出现重名,两个类其实是一个类, ...

  7. QT小插件类之QRoundProgressBar

    QRoundProgressBar类 1. 详细描述 QRoundProgressBar类能够实现一个圆形的进度图表,并且有和QProgressBar类似的API接口 1.1 继承关系 #includ ...

  8. Spring4分别整合mongo2.X和3.0

    1.pom文件添加: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-jav ...

  9. Vi命令详解

    Vi有三种模式,分别为命令行模式.一般模式和编辑模式.在命令行输入“Vi 文件名”,即可进入Vi.常用命令如下:一.一般模式翻页[Ctrl]+[f]: 向下翻一页,相当于[Page Down]按键.[ ...

  10. jquery1.9学习笔记 之选择器(基本元素四)

    ID选择器("#id") 描述: 选择与给出ID属性匹配的单元标签. 对于ID选择器,jquery使用JS的函数document.getElementById(),当一个标签附加到 ...