Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dp[100005];
- vector<int>p;
- int E;
- int rec(int s1){
- if(s1==E){
- return 0;
- }
- if(dp[s1]!=-1){
- return(dp[s1]);
- }
- int result=2e9;
- for(int i=0; i<p.size(); i++){
- if((p[i]<s1)and(p[i]+s1<=E)){
- result=min(result, rec(s1+p[i])+1);
- }
- }
- dp[s1]=result;
- return(result);
- }
- int main()
- {
- int S;
- cin>>S>>E;
- for(int i=0; i<100005; i++){
- dp[i]=-1;
- }
- for(int i=1; i<=100000; i++){
- vector<int>v;
- int n=i;
- int n1=0;
- while(n>0){
- int a=0;
- a=n%10;
- n/=10;
- v.push_back(a);
- }
- for(int j=0; j<=v.size()-1; j++){
- n1*=10;
- n1+=v[j];
- }
- if(n1==i){
- p.push_back(n1);
- }
- }
- cout<<rec(S);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement