比较简单的数位dp,但是要用到组合公式C,预处理吧。。。
1 /************************************************************** 2 Problem: 2425 3 User: rausen 4 Language: C++ 5 Result: Accepted 6 Time:0 ms 7 Memory:828 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <algorithm> 12 #include <cstring> 13 14 using namespace std; 15 typedef long long ll; 16 const int N = 55; 17 ll ans, c[N][N]; 18 int num[10]; 19 char s[N]; 20 int n; 21 22 ll calc(int x){ 23 ll res = 1; 24 for (int i = 0; i <= 9; ++i) 25 res *= c[x][num[i]], x -= num[i]; 26 return res; 27 } 28 29 int main(){ 30 scanf("%s", s + 1); 31 n = strlen(s + 1); 32 c[0][0] = 1; 33 for (int i = 0; i <= n; ++i) 34 for (int j = 0; j <= i; ++j) 35 c[i + 1][j] += c[i][j], c[i + 1][j + 1] += c[i][j]; 36 for (int i = 1; i <= n; ++i) 37 ++num[s[i] - '0']; 38 ans = 0; 39 for (int i = 1; i <= n; ++i){ 40 for (int j = 0; j < s[i] - '0'; ++j) 41 if (num[j]){ 42 --num[j]; 43 ans += calc(n - i); 44 ++num[j]; 45 } 46 --num[s[i] - '0']; 47 } 48 printf("%lld\n", ans); 49 return 0; 50 }
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen