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. TSP-旅行商问题

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  2. 《高级软件测试》11.15.全组完成jira安装,开始任务的部分书写

    今日任务完成情况如下: 小段:完成linux环境上jira的安装,并将jira的安装过程录制下来 小费:完成linux环境下jira的安装,开始部分任务的书写 小高:完成了jira的安装,并进一步熟悉 ...

  3. 微信小程序轮播图

    swiper标签 <!--index.wxml--> <swiper class="swiper" indicator-dots="true" ...

  4. Linux "零拷贝" sendfile函数中文说明及实际操作

    Sendfile函数说明 #include ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count); sendfile ...

  5. 移动端H5活动页优化方案

    背景 项目:移动端H5电商项目 痛点:慢!!! 初始方案:最基本的图片懒加载,静态资源放到cdn,predns等等已经都做了.但是还是慢,慢在哪? 显而易见的原因:由于前后端分离,所有的数据都由接口下 ...

  6. python 模块部分补充知识

    一.hashlib hashlib 模块主要用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法. 实例 ...

  7. JQ.ajax 各种参数及属性设置 ( 转载 )

    $.ajax({      type: "post",      url: url,      dataType:'html',      success: function(da ...

  8. Python内置函数(22)——list

    英文文档: class list([iterable]) Rather than being a function, list is actually a mutable sequence type, ...

  9. hdu1005 Number Sequence---找循环节

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1005题目大意: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + ...

  10. 彻底弄懂JS的事件冒泡和事件捕获

      先上结论:在事件执行流中有两种执行方式.一种是事件冒泡(即事件的执行顺序是从下往上执行的) ;  另一种是捕获(即事件的执行顺序是从上往下执行的); 阻止事件冒泡:   return false; ...