Codeforces #355C (Div. 2) 组合数

原题链接:http://www.codeforces.com/contest/677/problem/C

 

这题比较水,题意是每个字符有个0-63的编码,问你他可以又多少种等长的字符按位&而来。

 

显然把是0的位找出来,每个0可能是1&0,0&1,0&0,所以答案就是3^n,n是0的个数。。

 

这里写一个黑科技:__builtin_popcount()  是返回一个32位无符号的数的1的个数,貌似原理时是查表。。效率有待研究。

 

代码:

#include <bits/stdc++.h>

using namespace std;

int n,k,h;

int num(char c){
    if(c>='0'&&c<='9') return c-'0';
    else if(c>='A'&&c<='Z') return c-'A'+10;
    else if(c>='a'&&c<='z') return c-'a'+36;
    else if(c=='-') return 62;
    else if(c=='_') return 63;
}

string s;
int t[7]={1,3,9,27,81,243,729};
const int mo=1e9+7;
int main(){
    long long ans=1;
    cin>>s;
    int x;
    for(int i=0;i<s.size();i++){
        x=num(s[i]);
        ans=(ans*t[6-__builtin_popcount(x)])%mo;
    }
    cout<<ans<<endl;

    return 0;
}


posted @ 2016-06-22 17:40  zhangxianlong  阅读(101)  评论(0编辑  收藏  举报