Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dp[0][0] = 0;
- queue<pair<int, int> > q;
- q.push({0, 0});
- while (!q.empty()) {
- pair<int, int> v = q.front();
- q.pop();
- for (int dig = 0; dig < 10; dig++) {
- pair<int, int> nv = {v.first + dig, (10 * v.second + dig) % d};
- if (nv.first > s) continue;
- if (dp[nv.first][nv.second] == -1 || dp[nv.first][nv.second] > dp[v.first][v.second] + 1) {
- dp[nv.first][nv.second] = dp[v.first][v.second] + 1;
- q.push(nv);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement