Help, segmentaion fault in dp problem

Правка en1, от liveoverflow, 2020-05-22 13:46:59

Q)subtract a digit from the given number (the digit must occur in the number) and get a new number. Repeat this operation until the number equals zero. count the minimum number of operations needed to reduce the number to zero.

submission link -> 80890640

vector<int>dp(1000000+1,1e9);
int f(int n){
    if(dp[n]!=1e9) return dp[n];
    int te = n;
    while(te){
     if(te%10!=0) dp[n]=min(dp[n],1+f(n-te%10));
     te/=10;
    } 
     return dp[n];
}
int main(){
    int t=1; //cin>>t;
    while(t--){
       int n; cin>>n;
        dp[0]=0;
        cout<< f(n);
    }
}
Теги #dynamic programing, #dp, #help, segmentation fault

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский liveoverflow 2020-05-22 13:50:26 136
en1 Английский liveoverflow 2020-05-22 13:46:59 668 Initial revision (published)