题解
一道搜索+模拟
搜索每一位可以放哪个值(\([0,9]\)),然后累加搜索下一位
注意细节
code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll f[10][105]={0};
ll n,k;
ll ss(ll now,ll left)
{
if(f[now][left])return f[now][left];
if(now==n)
{
f[now][left]=min(left+1,10LL);//这里也是一样!!
return f[now][left];
}
ll ans=0;
for(ll i=0;i<=min(9LL,left);i++) ans+=ss(now+1,left-i);//位数必须在09之间!!
f[now][left]=ans;
return ans;
}
int main()
{
ll t=1;
//cin>>t;
while(t--)
{
cin>>n>>k;
cout<<ss(1,k)-1<<endl;
memset(f,0,sizeof f);
}
return 0;
}
标签:T432580,ver,ll,hard,long,now,left
From: https://www.cnblogs.com/pure4knowledge/p/18061813