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

要求从左上角走到右下角的最大值。

如果n,m中有奇数则可以全部走完。否则需要在(i+j-2)%2 == 1的点中选择一个最小值绕过。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MAXN 300005
#define MIN 0
#define MAX 1000001 int main()
{
int n,m;
ll sum;
char ch;
int x;
//freopen("1007.txt","r",stdin);
while(scanf("%d%d",&n,&m) != EOF)
{
sum = 0;
int minx = 100000;
int mini=-1,minj=-1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
scanf("%d",&x);
sum += x;
if((i+j-2)%2)
{
if(x < minx)
{
minx = x;
mini = i;
minj = j;
}
}
}
if(n % 2 || m % 2)
{
printf("%I64d\n",sum);
if(n % 2)
{
for(int k = 1; k <= n; k++)
{
if(k % 2)
ch = 'R';
else
ch = 'L';
for(int i = 1; i <= m-1; i++)
printf("%c",ch);
if(k != n)
printf("D");
} }
else
{
for(int k = 1; k <= m; k++)
{
if(k % 2)
ch = 'D';
else
ch = 'U';
for(int i = 1; i <= n-1; i++)
printf("%c",ch);
if(k != m)
printf("R");
}
}
}
else
{
printf("%I64d\n",sum-minx);
int k=1;
while(1)
{
if(mini%2&&k==mini) break;
if(mini%2==0&&(k+1)==mini) break;
for(int i=2; i<=m; i++)
if(k%2) printf("R");
else printf("L");
printf("D");
k++;
}
if(mini%2)
{
int cx=k;
int cy=1;
while((cy+1)!=minj)
{
printf("DRUR");
cy+=2;
}
printf("DR");
cx++;
cy++;
while(cy!=m)
{
printf("RURD");
cy+=2;
}
k+=2;
}
else
{
int cx=k;
int cy=1;
while(cy!=minj)
{
printf("DRUR");
cy+=2;
}
printf("RD");
cx++;
cy++;
while(cy!=m)
{
printf("RURD");
cy+=2;
}
k+=2;
}
for(int i=k; i<=n; i++)
{
printf("D");
for(int j=2; j<=m; j++)
if(i%2) printf("L");
else printf("R");
}
}
printf("\n");
}
return 0;
}

  

2015 多校联赛 ——HDU5402(模拟)的更多相关文章

  1. 2015 多校联赛 ——HDU5319(模拟)

    Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  2. 2015 多校联赛 ——HDU5373(模拟)

    Problem Description In this problem, we should solve an interesting game. At first, we have an integ ...

  3. 2015 多校联赛 ——HDU5334(构造)

    Virtual Participation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  4. 2015 多校联赛 ——HDU5302(构造)

    Connect the Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  5. 2015 多校联赛 ——HDU5294(最短路,最小切割)

    Tricks Device Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  6. 2015 多校联赛 ——HDU5325(DFS)

    Crazy Bobo Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  7. 2015 多校联赛 ——HDU5316(线段树)

    Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...

  8. 2015 多校联赛 ——HDU5323(搜索)

    Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 2015 多校联赛 ——HDU5301(技巧)

    Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...

随机推荐

  1. 实现mypwd

    1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试mypwd 提交过程博客的链接 代码如图

  2. DML数据操作语言之增加,删除,更新

    1.数据的增加 数据的增加要用到insert语句  ,基本格式是: insert into <表名> (列名1,列名2,列名3,......) values (值1,值2,值3,..... ...

  3. java图片处理开源框架

    java图片处理开源框架 以前一直不明白,java开源框架什么意思,搜集资料得出以下结论 其实java框架可以理解为一个工具或者一个插件,将一个公用的.常用的技术封装起来,处理一些基础的.繁琐的问题. ...

  4. js的构造函数共用事例

    在使用构造函数去实现一种功能时,我们有时候往往需要实现这个功能,会因此产生多个堆内对象.这样就会造成堆内存滥用.占用不该占用的空间.为此我们可以利用函数把共用的内容封装起来.放便我们的使用.很多东西其 ...

  5. Python内置函数(39)——help

    英文文档: help([object]) Invoke the built-in help system. (This function is intended for interactive use ...

  6. Python内置函数(32)——all

    英文文档: all(iterable) Return True if all elements of the iterable are true (or if the iterable is empt ...

  7. Python基础学习篇章四

    一. Python数据类型之字典 1. 键的排序:for循环 由于字典不是序列,因此没有可靠的从左至右的顺序.这就导致当建立一个字典,将它打印出来,它的键也许会以与我们输入时的不同的顺序出现.有时候我 ...

  8. python中导入模块的本质, 无法导入手写模块的解决办法

    最近身边一些朋友发生在项目当中编写自己模块,导入的时候无法导入的问题. 下面我来分享一下关于python中导入模块的一些基本知识. 1 导入模块时寻找路径 在每一个运行的python程序当中,都维护了 ...

  9. Android TabLayout 在宽屏幕上tab不能平均分配的问题解决

    当TabLayout 在宽屏幕的设备上,如平板横屏的时候,tab的宽度超过一定值后,就不在平均分配宽度,而是居中显示.此时设置 app:tabMode="fixed"或者 top_ ...

  10. redis中的aof模式,产生的是增量数据,还是全量数据?

    先说答案:全量数据. 1.修改redis.conf,开启rdb,禁用aof 上面这个是持久化文件的路径,我们ll看下: 2.启动redis后,cli查看里面的key [root@mini1 redis ...