// Problem: P2602 [ZJOI2010]数字计数 // Contest: Luogu // URL: https://www.luogu.com.cn/problem/P2602 // Memory Limit: 125 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h> usingnamespace std; #define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} //#define M //#define mo //#define N int n, m, i, j, k; int f[30][2][2], s[30][15][2][15], a[30], ans[15]; int x, y;
intdfs(int k, int p, int o) { if(k==0) return1; if(f[k][p][o]!=-1) { for(int i=0; i<=9; ++i) ans[i]+=s[k][p][o][i]; return f[k][p][o]; } int i, j, q, z; for(i=j=0; i<=9; ++i) { if(!p && i>a[k]) break; q=dfs(k-1, p||(i<a[k]), o||i); j+=q; if(i||o) ans[i]+=q*m, s[k][p][o][i]+=q*m; for(z=0; z<=9; ++z) s[k][p][o][i]+=s[k-1][p||(i<a[k])][o||i][z]; } return f[k][p][o]=j; }