###### HDU 5402 Travelling Salesman Problem（组合数学+构造）

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<ctime>
#define eps 1e-6
#define LL long long
#define pii pair<int, int>
using namespace std;

const int MAXN = 110;
//const int INF = 0x3f3f3f3f;
int n, m;
int G[MAXN][MAXN];
void print_path1(int ans) {
cout << ans << endl;
int dir = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j < m; j++)
if(!dir) putchar('R');
else putchar('L');
if(i<n) putchar('D');
dir ^= 1;
}
puts("");
}
void print_path2(int ans) {
cout << ans << endl;
int dir = 0;
for(int i = 1; i <= m; i++) {
for(int j = 1; j < n; j++)
if(!dir) putchar('D');
else putchar('U');
if(i<m) putchar('R');
dir ^= 1;
}
puts("");
}
void print_path3(int ans, int x, int y) {
cout << ans << endl;
int dir = 0, tmp = (x&1) ? x : x-1;
for(int i = 1; i < tmp; i++) {
for(int j = 1; j < m; j++)
if(!dir) putchar('R');
else putchar('L');
putchar('D');
dir ^= 1;
}
int tmp2 = (y&1) ? y : y-1;
for(int i = 1; i < tmp2; i+=2) printf("DRUR");
if(x != tmp) {
printf("RD");
if(y<m-1) putchar('R');
}
else {
printf("DR");
if(y<m-1) putchar('R');
}
for(int i = tmp2+2; i < m; i+=2)
if(i != m-1) printf("URDR");
else printf("URD");
if(tmp+2<=n) putchar('D');
dir = 1;
for(int i = tmp+2; i <= n; i++) {
for(int j = 1; j < m; j++)
if(!dir) putchar('R');
else putchar('L');
if(i<n) putchar('D');
dir ^= 1;
}
puts("");
}
int main() {
//freopen("input.txt", "r", stdin);
int kase = 0;
while(cin >> n >> m) {
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
scanf("%d", &G[i][j]);
ans += G[i][j];
}
}
if(n&1) print_path1(ans);
else if(m&1) print_path2(ans);
else {
int x, y, minv = 100000;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(((i+j)&1) && G[i][j]<minv) {
minv = G[i][j];
x = i;
y = j;
}
}
}
print_path3(ans-minv, x, y);
}
}
return 0;
}



#### HDU 5402 Travelling Salesman Problem(棋盘黑白染色)——多校练习9

2015-08-18 19:13:19

#### <OJ_Sicily>Travelling Salesman Problem

2016-05-09 15:43:03

#### 规律，模拟，贪心（Travelling Salesman Problem，HDU 5402）

2017-07-16 20:13:35

#### 旅行商问题(travelling salesman problem, TSP) 解题报告

2013-04-14 12:51:22

#### hdu 5402 Travelling Salesman Problem 模拟构造

2015-08-19 15:21:06

#### 【HDU 5402】Travelling Salesman Problem（构造）

2015-08-18 21:14:17

#### 构造 - HDU 5402 Travelling Salesman Problem

2017-03-05 17:20:31

#### HDU 5402 (构造题) Travelling Salesman Problem

2015-08-18 22:05:56

#### hdu 5402 Travelling Salesman Problem(构造+模拟)

2015-08-21 15:27:21

#### HDU 5402 Travelling Salesman Problem

2015-08-18 17:13:20

## 不良信息举报

HDU 5402 Travelling Salesman Problem（组合数学+构造）