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. 201621123060 《Java程序设计》第五周学习总结

    1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 继承.多态.抽象类与接口 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般不需要出现过多的字. 2. 书面作业 作 ...

  2. from nltk.book import * 出错的解决方法

    import nltknltk.download() 在使用上面命令安装了nltk库并运行下载后,再输入from nltk.book import * 往往会出现这样的错误提示: 出现这种错误往往是由 ...

  3. 《招一个靠谱的移动开发》iOS面试题及详解(上篇)

    以下问题主要用于技术的总结与回顾 主要问题总结 单例的写法.在单利中创建数组应该注意些什么. NSString 的时候用copy和strong的区别. 多线程.特别是NSOperation 和 GCD ...

  4. Apache自带 ab压测工具 Windows配置使用说明 - 随笔记录

    我们先来了解一下ab工具的概念,摘自网络: ab是apache自带的压力测试工具.ab非常实用,它不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试.比如ngin ...

  5. MSIL实用指南-一维数组的操作

    本篇讲解怎么生成和操作一维数组.各种数组类型创建的步骤是一样的,但是加载和保存步骤有所不同. 一.创建数组所有类型的一维数组创建都是一样的,分三步.1.加载数组长度2.生成指令 Newarr < ...

  6. php里面的变量的使用

    php里面的变量一般可以直接使用不需要声明,但是这种var_dump($a);就会报错,还有sql语句里面如果某个变量为空也会报错. 如果变量为null,空,未声明都==false,但是不===fal ...

  7. 安装CentOS7,连接mysql提示密码错误

    1.grep 'temporary password' /var/log/mysqld.log 如果上面命令没有查看到密码 2.修改my.cnf文件.在mysqld下加入skip-grant-tabl ...

  8. python全栈开发-re模块(正则表达式)应用(字符串的处理)

    一.概述 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,要讲他的具体用法要讲一本书!它内嵌在Python中,并通过 re 模块实现.你可以为想要匹配的相应字符串集指定规则:该 ...

  9. Ubuntu下安装最新sublime

    1. Install the GPG key: wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key ...

  10. Github学习笔记-不定时更新

    最近在搞一个外包项目,有个非常厉害的师兄带我,他写后端,我负责前端部分,项目合作需要用到github,这也是早晚要接触,记录下项目过程中对github/git使用的学习笔记. 1.在网上看了一些教程之 ...