Codeforces Round #355 (Div. 2)-C

C. Vanya and Label
题目链接:http://codeforces.com/contest/677/problem/C

While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string sand wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.

To represent the string as a number in numeral system with base 64 Vanya uses the following rules:

  • digits from '0' to '9' correspond to integers from 0 to 9;
  • letters from 'A' to 'Z' correspond to integers from 10 to 35;
  • letters from 'a' to 'z' correspond to integers from 36 to 61;
  • letter '-' correspond to integer 62;
  • letter '_' correspond to integer 63.
Input

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Output

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo109 + 7.

Examples
input
z
output
3
input
V_V
output
9
input
Codeforces
output
130653412
Note

For a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.

In the first sample, there are 3 possible solutions:

  1. z&_ = 61&63 = 61 = z
  2. _&z = 63&61 = 61 = z
  3. z&z = 61&61 = 61 = z

题意:给定一个字符串,每个字符定义如上说明。然后问有多少长度和给定的串长度相同并且与给定的串位与之后还是等于给定的串。 输出结果MOD 1e9+7

思路:考虑每个字符,因为有位于运算所以先把字符对应的数字转换为二进制,可以发现0-63只需6位二进制表示。然后考虑每一位i[0-5],如果该位为1,那么要使得&后与原串相同,那么对应该位置只能1[1&1=1], 但是如果该位为0,那么对应位置就可以是0&0,0&1,1&0共3种。最后根据组合乘法计算总数。

#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdio>
#include<bitset>
using namespace std;
typedef long long int LL;
#define INF 0x3f3f3f3f
const int MAXN = 100000 + 5;
const int MOD = 1e9 + 7;
char str[MAXN];
int getnum(char ch){
    int num;
    if (ch >= '0'&&ch <= '9'){
        num = ch - '0';
    }
    else if (ch >= 'A'&&ch <= 'Z'){
        num = (ch - 'A') + 10;
    }
    else if (ch >= 'a'&&ch <= 'z'){
        num = (ch - 'a') + 36;
    }
    else if (ch == '-'){
        num = 62;
    }
    else{
        num = 63;
    }
    return num;
}
LL powmod(LL x, LL n){
    LL ans = 1;
    while (n){
        if (n & 1){
            ans = (ans*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ans;
}
int main(){
    while (~scanf("%s", str)){
        LL ans = 0; int len = strlen(str);
        for (int i = 0; i < len; i++){
            bitset<6> num(getnum(str[i]));
            for (int j = 0; j < 6; j++){
                if (num[j] == 0){
                    ans++;
                }
            }
        }
        printf("%I64d\n", powmod(3,ans)%MOD);
    }
    return 0;
}

 

posted @ 2016-06-02 15:38  キリト  阅读(181)  评论(0编辑  收藏  举报