You are viewing a single comment's thread. Return to all comments →
Enjoy
vector<int> ini(int n){ vector<int> m(n+1,-1); queue<int> q; q.push(0); m[0]=0; int step; int curr; while(q.size()>0){ curr=q.front(); step=m[curr]+1; q.pop(); //curr+1 case if(m[curr+1]==-1 && curr<n){ // if(curr+1==n){ // return step; // } q.push(curr+1); m[curr+1]=step; } //all multiples of curr if(curr>=2){ for(int i=2;i<=curr && i*curr<=n;i++){ if(m[curr*i]==-1){ // if (curr*i==n) { // return step; // } q.push(curr*i); m[curr*i]=step; } } } } return m; } int downToZero(int n) { static vector<int> m=ini(1000000); return m[n]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
Enjoy