AcWing 1082. 此题输入不能支持java, 头疼
原题链接
中等
作者:
acw_weian
,
2020-07-27 16:40:42
,
所有人可见
,
阅读 626
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 12;
int f[N][N];
void init(){
for(int i = 0; i <= 9; i++) f[1][i] = 1;
for(int i = 2; i <= N; i++){
for(int j = 0; j <= N; j++){
for(int k = j; k <= 9; k++){
f[i][j] += f[i - 1][k];
}
}
}
}
int dp(int n){
if( n == 0) return 1;
int res = 0, last = 0;
vector<int> a;
while(n != 0){
a.push_back(n % 10);
n /= 10;
}
for(int i = a.size() - 1; i >= 0; i--){
int x = a[i];
if(x < last) break;
for(int j = last; j < x; j++){
res += f[i + 1][j];
}
last = x;
if(i == 0) res++;
}
return res;
}
int main(){
init();
int l, r;
while(cin>>l>>r) cout<< dp(r) - dp(l - 1) << endl;
return 0;
}
java输入可以这样写