P1874 快速求和
#include <bits/stdc++.h>
using namespace std;
int f(const string& s, int n, int x, int y, int z) {
int len = s.size();
if (x == len) {
return z == n ? y : INT_MAX;
}
int ans = INT_MAX;
int num = 0;
for (int i = x; i < len; ++i) {
num = num * 10 + (s[i] - '0');
if (num > n) break;
ans = min(ans, f(s, n, i + 1, y + 1, z + num));
}
return ans;
}
int main() {
string s;
int n;
cin >> s >> n;
int ans = f(s, n, 0, -1, 0);
if (ans == INT_MAX) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
}