Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int a[4];
- int ans = 200;
- void dfs (int x, int b[4]) {
- for (int i = 0; i < 4; i ++) {
- cout << b[i] << ' ';
- }
- cout << x << endl;
- if (x == 0) {
- // b: 2 1 0 6
- // 20 16
- int res = (b[0] + b[1]) * 10 + b[2] + b[3];
- ans = min(ans, res);
- return;
- }
- for (int i = 0; i <= 4; i ++) {
- if(b[i] != -1) continue;
- int c[4];
- for (int j = 0; j < 4; j ++) c[j] = b[j];
- c[i] = a[x - 1];
- dfs(x - 1, c);
- }
- }
- int main() {
- cin >> n;
- for (int i = 0; i < 4; i ++) {
- a[i] = n % 10;
- n /= 10;
- }
- cout << "a: ";
- for (int i = 0; i < 4; i ++) cout << a[i] << ' ';
- cout << endl;
- int s[4] = {-1, -1, -1, -1};
- dfs(4, s);
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement