标签:
Description
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 s and 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:
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 ‘_‘.
Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.
z
3
V_V
9
Codeforces
130653412
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:
给我们一下字符串,问我们可以通过&后,值依然和题目上规定的相同
我们当然可以先把0~63的先全部&一下,存下结果,然后,就一个字符一个字符的判断就好啦~
1 #include<iostream> 2 #include<stdio.h> 3 #include<map> 4 using namespace std; 5 map<int,int> q; 6 int main() 7 { 8 for(int i=0;i<=63;i++) 9 { 10 for(int j=0;j<=63;j++) 11 { 12 q[i&j]++; 13 } 14 } 15 int pos; 16 long long num=1; 17 string s; 18 cin>>s; 19 for(int i=0;i<s.length();i++) 20 { 21 if(s[i]>=‘0‘&&s[i]<=‘9‘) 22 { 23 pos=s[i]-‘0‘; 24 } 25 else if(s[i]>=‘A‘&&s[i]<=‘Z‘) 26 { 27 pos=s[i]-‘A‘+10; 28 } 29 else if(s[i]>=‘a‘&&s[i]<=‘z‘) 30 { 31 pos=s[i]-‘a‘+36; 32 } 33 else if(s[i]==‘-‘) 34 { 35 pos=62; 36 } 37 else if(s[i]==‘_‘) 38 { 39 pos=63; 40 } 41 num=num*q[pos]%1000000007; 42 } 43 cout<<num<<endl; 44 return 0; 45 }
Codeforces Round #355 (Div. 2) C
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5553312.html