Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dp[100005];
- int main()
- {
- int s;
- int E;
- cin>>s>>E;
- vector<int>v;
- vector<int>p;
- for(int i=0; i<100005; i++){
- dp[i]=2e9;
- }
- 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);
- }
- }
- dp[s]=0;
- for(int i=s; i<=E; i++){
- for(int j=0; j<p.size(); j++){
- if((p[j]<i)and(i+p[j]<=E)){
- dp[p[j]+i]=min(dp[p[j]+i], dp[i]+1);
- }
- }
- }
- cout<<dp[E];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement