daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Oct 20th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top