fork(1) download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. string S;int p;
  5. int main(){
  6. cin>>S>>p;int b[12];
  7. int n=S.size();int res=0;
  8. for(int i=0;i<(1<<(n-1));i++){
  9. for(int j=0;j<n-1;j++){b[j]=(i/(1<<j))%2;}
  10. string T="";long long cnt=0;
  11. for(int j=0;j<n;j++){
  12. T+=S[j];
  13. if(j<n-1){
  14. if(b[j]>=1){
  15. long long B=stoll(T);
  16. cnt+=B;T="";
  17. }
  18. }
  19. }
  20. if(T!=""){cnt+=stoll(T);}
  21. if(cnt<=p){res++;}
  22. }
  23. cout<<res<<endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3464KB
stdin
1355
50
stdout
3