题目:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1009
代码:
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
long dp(long n)
{
long count=0;
if(n==0)
count=0;
else if(n>0&&n<10)
count=1;
else
{
int bit=0;
long hight=n;
while(hight>=10)
{
hight=hight/10;
bit++;
}
int weight=(int)pow(10,bit);
if(hight==1)
{
count=dp(weight-1)+dp(n-weight)+n-weight+1;
}
else
{
count=hight*dp(weight-1)+dp(n-weight*hight)+weight;
}
}
return count;
}
int main()
{
long N;
cin>>N;
long count1=dp(N);
cout<<count1<<endl;
return 0;
}