Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- using namespace std;
- int s,e;
- vector <int> v;
- int dp[100000];
- int rek(int x)
- {
- if(x==e)
- {
- return 0;
- }
- if(dp[x]!=-1)
- {
- return dp[x];
- }
- int rez=1e5;
- for(int i=0;i<v.size();i++)
- {
- if(v[i]<x && v[i]+x<=e)
- {
- rez=min(rez,rek(x+v[i])+1);
- }
- }
- dp[x]=rez;
- return rez;
- }
- int main()
- {
- cin>>s>>e;
- for (int i=0;i<100000;i++)
- {
- dp[i]=-1;
- }
- for(int i=1;i<100000;i++)
- {
- int cifri[6]={-1};
- int j=0;
- int il=i;
- while(il>0)
- {
- cifri[j]=il%10;
- j++;
- il/=10;
- }
- int k=0;
- for(int y=0;y<j;y++)
- {
- if(cifri[y]!=cifri[j-y-1])
- {
- k=-1;
- }
- }
- if(k==0)
- {
- v.push_back(i);
- }
- }
- cout<<rek(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement