zoukankan      html  css  js  c++  java
  • BZOJ2425: [HAOI2010]计数

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2425

    其实能够构成的数就是原数的排列(算前导0),然后组合计数一下就可以了。

    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #define rep(i,l,r) for (int i=l;i<=r;i++)
    #define down(i,l,r) for (int i=l;i>=r;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define maxn 50050
    #define ll long long
    using namespace std;
    int cnt[20],n;
    ll ans,c[60][60];
    char s[60];
    int read(){
        int x=0,f=1; char ch=getchar();
        while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
        while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    ll cal(int x){
        ll res=1;
        int now=x;
        rep(j,0,9) {
            res*=c[now][cnt[j]],now-=cnt[j];     
        }
        return res;
    }
    int main(){
        c[0][0]=1;
        rep(i,1,50){
            c[i][0]=1;
            rep(j,1,i) c[i][j]=c[i-1][j-1]+c[i-1][j];
        }
        scanf("%s",s+1); n=strlen(s+1);
        rep(i,1,n) ++cnt[s[i]-'0'];
        rep(i,1,n) {
            rep(j,0,(s[i]-'0')-1) if (cnt[j]){
                --cnt[j];
                ans+=cal(n-i);
                ++cnt[j];
            }
            --cnt[s[i]-'0'];
        }
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    网页加载进度条
    BFC
    Java — 基础语法
    Python — 多进程
    Python — 进程和线程
    Python — 面向对象进阶2
    Python — 面向对象编程基础
    Linnux 05
    Linnux 04
    Linnux 03
  • 原文地址:https://www.cnblogs.com/ctlchild/p/5011377.html
Copyright © 2011-2022 走看看