908G New Year and Original Order
分析
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
#define add(x,y) x=(x+y)%mod
const int mod = 1e9+7;
char s[1100];
int a[1100],dp[720][720][10][2];
signed main(){
int n,m,i,j,k,t;
scanf("%s",s+1);
n=strlen(s+1);
for(i=1;i<=n;i++)a[i]=s[i]-'0';
for(i=0;i<=9;i++)dp[0][0][i][0]=1;
for(i=1;i<=n;i++)
for(j=0;j<=i;j++)
for(k=0;k<=9;k++){
for(t=0;t<=9;t++)
add(dp[i][j+(t>=k)][k][1],dp[i-1][j][k][1]);
for(t=0;t<a[i];t++)
add(dp[i][j+(t>=k)][k][1],dp[i-1][j][k][0]);
add(dp[i][j+(t>=k)][k][0],dp[i-1][j][k][0]);
}
int wh=1,Ans=0;
for(i=1;i<=n;i++){
for(j=1;j<=9;j++)add(Ans,wh*(dp[n][i][j][0]+dp[n][i][j][1])%mod);
wh=(wh*10+1)%mod;
}
cout<<Ans;
return 0;
}