题解
2023-09-01 10:51:28
发布于:广东
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
bool vis[110][110][110];
int x, y, k, m, sol;
void ff(int curX, int curY, int curK) {
if (vis[curX][curY][curK] || curK > k) return;
vis[curX][curY][curK] = true;
sol = min(sol, abs(m - (curX + curY)));
ff(x, curY, curK + 1);
ff(curX, y, curK + 1);
ff(0, curY, curK + 1);
ff(curX, 0, curK + 1);
int leftoverX = (curX + curY > y ? curX + curY - y : 0);
int leftoverY = (curY + curX > x ? curY + curX - x : 0);
ff(leftoverX, min(y, curY + curX), curK + 1);
ff(min(x, curX + curY), leftoverY, curK + 1);
}
int main() {
cin >> x >> y >> k >> m;
sol = m;
ff(0, 0, 0);
cout << sol << '\n';
}
这里空空如也
有帮助,赞一个