其实感觉这道题在D简单了(但我都没做到这一题,路径最多的方式只有一种,将所有的边都走一遍,从第一行开始,向右走到头,然后向左回来,向下一格,向右走到头,然后上下左重复直到第一列,如此重复直到最后一行,最后一步为向上到第一行第一列,注意输出的时候要判断一下0的情况
#include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long long LL; void run_case() { int n, m, k; cin >> n >> m >> k; vector<pair<int,string>> store, ans; int cnt = 0; for(int i = 1; i <= n; ++i) { store.push_back(make_pair(m-1, "R")); cnt += store.back().first * store.back().second.size(); if(i == 1) store.push_back(make_pair(m-1, "L")); else store.push_back(make_pair(m-1, "UDL")); cnt += store.back().first * store.back().second.size(); if(i == n) store.push_back(make_pair(n-1, "U")); else store.push_back(make_pair(1, "D")); cnt += store.back().first * store.back().second.size(); } if(cnt < k) { cout << "NO "; return; } while(cnt > k) { string now = store.back().second; int cur = store.back().first*now.size(); store.pop_back(); cnt -= cur; if(cnt >= k) continue; cur = k - cnt; if(cur / now.size()) store.push_back(make_pair(cur/now.size(), now)); now.resize(cur%now.size()); if(now.size()) store.push_back(make_pair(1, now)); cnt = k; } cout << "YES "; for(auto i : store) { if(i.first) ans.push_back(i); } cout << ans.size() << " "; for(auto i : ans) { cout << i.first << " " << i.second << " "; } } int main() { ios::sync_with_stdio(false), cin.tie(0); //cout.setf(ios_base::showpoint);cout.precision(10); //int t; cin >> t; //while(t--) run_case(); cout.flush(); return 0; }