Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. dp[0][0] = 0;
  2. queue<pair<int, int> > q;
  3. q.push({0, 0});
  4.  
  5. while (!q.empty()) {
  6.     pair<int, int> v = q.front();
  7.     q.pop();
  8.     for (int dig = 0; dig < 10; dig++) {
  9.         pair<int, int> nv = {v.first + dig, (10 * v.second + dig) % d};
  10.         if (nv.first > s) continue;
  11.         if (dp[nv.first][nv.second] == -1 || dp[nv.first][nv.second] > dp[v.first][v.second] + 1) {
  12.             dp[nv.first][nv.second] = dp[v.first][v.second] + 1;  
  13.             q.push(nv);
  14.         }
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement