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:
- 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.
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:
- z&_ = 61&63 = 61 = z
- _&z = 63&61 = 61 = z
- z&z = 61&61 = 61 = z
题目大意:
给你一个字符串,并且告诉你每个字符的价值,让你统计一共有多少个字符串,和原字符串等长,并且每一位的&之后的值还是原字符串的值。
思路:
对于一个二进制位来讲,如果一个位子是1.那么这个字符进行替换的字符这个位子肯定也是1才行。
那么如果一个位子是0.那么这个字符进行替换的字符这个位子可能是三种情况:0&1 1&0 0&0;
那么我们的任务就是统计一个位子上的字符的二进制有多少个0.有一个乘一个3即可。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
#define mod 1000000007
#define ll __int64
char a[100700];
ll vis[100];
int judge(char a)
{
if(a>='0'&&a<='9')return a-'0';
if(a>='A'&&a<='Z')return a-'A'+10;
if(a>='a'&&a<='z')return a-'a'+36;
if(a=='-')return 62;
if(a=='_')return 63;
}
int main()
{
while(~scanf("%s",a))
{
ll output=1;
int n=strlen(a);
for(int i=0;i<n;i++)
{
int tmp=judge(a[i]);
int cnt=0;
while(tmp)
{
cnt++;
if(tmp%2==0)
output*=3;
tmp/=2;
output%=mod;
}
if(cnt<6)
{
while(cnt<6)output*=3,cnt++,output%=mod;
}
}
printf("%I64d\n",output);
}
}
本文介绍了一道关于字符串匹配的问题,需要统计与给定字符串等长且按位与运算后值相同的字符串数量。通过分析字符对应的数值及二进制表示,采用高效算法求解并给出AC代码。
302

被折叠的 条评论
为什么被折叠?



