// // 9th homework of Algorithm Designing and Analyzing in spring semester, 2020 // // Introduction: // // // Author: // Yihang Bao // 2018011890 // Created by Yihang Bao on 2020/4/21. // //
#include<bits/stdc++.h> #define INF 0x3f3f3f3 #define maxn 100100 typedeflonglong ll; usingnamespacestd; #define rep(i, n, args...) for (ll i = 0, ##args; i < n; i++) #define repr(i, s, e, args...) for (ll i = s, ##args; i < e; i++) #define erg(i, u, args...) for (ll i = vtx[u], ##args; ~i; i = eg[i].nxt) #define fulset(x, v) memset(x, v, sizeof(x))
// // 9th homework of Algorithm Designing and Analyzing in spring semester, 2020 // // Introduction: // // // Author: // Yihang Bao // 2018011890 // Created by Yihang Bao on 2020/5/11. // //
#include<bits/stdc++.h> #define INF 0x3f3f3f3 #define maxn 100100 typedeflonglong ll; usingnamespacestd; #define rep(i, n, args...) for (ll i = 0, ##args; i < n; i++) #define repr(i, s, e, args...) for (ll i = s, ##args; i < e; i++) #define erg(i, u, args...) for (ll i = vtx[u], ##args; ~i; i = eg[i].nxt) #define fulset(x, v) memset(x, v, sizeof(x))
structwid { int v1; int v2; int width; bool chose; };
// // 10th homework of Algorithm Designing and Analyzing in spring semester, 2020 // // Introduction: // // // Author: // Yihang Bao // 2018011890 // Created by Yihang Bao on 2020/5/13. // //
#include<bits/stdc++.h> #define INF 0x3f3f3f3 #define maxn 100100 typedeflonglong ll; usingnamespacestd; #define rep(i, n, args...) for (ll i = 0, ##args; i < n; i++) #define repr(i, s, e, args...) for (ll i = s, ##args; i < e; i++) #define erg(i, u, args...) for (ll i = vtx[u], ##args; ~i; i = eg[i].nxt) #define fulset(x, v) memset(x, v, sizeof(x));
int n,c1,c2; int w[100010]; int wn,wb; int wr[100010]; bool pat[100010]; bool flag;
voidbacktrack(int level) { if (level == n) { wb = max(wb,wn); return; } if (wn+w[level+1]<=c1) { wn += w[level+1]; backtrack(level+1); wn -= w[level+1]; } if (wn+wr[level+1]>wb) backtrack(level+1); return; }
voidbacktrack_plan(int level) { if (flag) return; if (level == n) { cout << "ship1: "; for (int i=1;i<=n;i++) if (pat[i]) cout << w[i] << " "; cout << endl; cout << "ship2: "; for (int i=1;i<=n;i++) if (!pat[i]) cout << w[i] << " "; cout << endl; flag = true; return; } pat[level+1] = false; if (wn+w[level+1]<=c1) { wn += w[level+1]; pat[level+1] = true; backtrack_plan(level+1); pat[level+1] = false; wn -= w[level+1]; } if (wn+wr[level+1]>=wb) backtrack_plan(level+1); return; }
intmain() { /* 样例输入: 4 12 8 8 6 2 3 表示有4件物品,第一艘船载重c1=12,第二艘船载重c2=8,第二行是4个物品的质量 */ int sum = 0; flag = false; cin >> n >> c1 >> c2; for (int i=1;i<=n;i++) { cin >> w[i]; sum += w[i]; } wn = 0; wb = 0; wr[n] = w[n]; for (int i=n-1;i>=1;i--) wr[i] = wr[i+1]+w[i]; backtrack(0); wn = 0; if (c2<sum-wb) cout << "No such plan" << endl; else { backtrack_plan(0); } }