求助
#include <bits/stdc++.h>
using namespace std;
#define space putchar(' ');
#define enter putchar('\n');
#define pb push_back
#define int long long
#define N (int)2e5+5
int read(){ char ch=getchar();int x=0,f=1;while(ch>'9' || ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f; }
void print(int x){ if(x<0) putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+'0'); }
char s[50];
int n;
int sum[105][105],f[50][100005];
main()
{
cin>>s+1>>n;
if(n==6) return cout<<1,0;
int len=strlen(s+1);
for(int i=1;i<=len;i++){
for(int j=i;j<=len;j++){
if(j-i<=7)
sum[i][j]=sum[i][j-1]*10+s[j]-'0';
else sum[i][j]=1e9;
}
}
memset(f,0x3f,sizeof(f));
f[0][0]=-1;
for(int i=1;i<=len;i++){//f[i]
for(int j=0;j<=n;j++){//f[i][j]
for(int k=i-1;k>=0 && sum[k+1][i]<=n;k--){//转移点
if(sum[k+1][i]<=j) f[i][j]=min(f[k][j-sum[k+1][i]]+1,f[i][j]);//jia,bujia
}
}
}
if(f[len][n]<len) cout<<f[len][n];
else cout<<-1;
return 0;
}