码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ2425 [HAOI2010]计数

时间:2015-03-17 21:28:10      阅读:621      评论:0      收藏:0      [点我收藏+]

标签:

比较简单的数位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 }
View Code

 

BZOJ2425 [HAOI2010]计数

标签:

原文地址:http://www.cnblogs.com/rausen/p/4345405.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!