zoukankan      html  css  js  c++  java
  • [暴力枚举]Codeforces Vanya and Label

    Vanya and Label
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.
    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 modulo 109 + 7.

    Examples
    input
    Copy
    z
    output
    Copy
    3
    input
    Copy
    V_V
    output
    Copy
    9
    input
    Copy
    Codeforces
    output
    Copy
    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

    题意:给你一个字符串s,把字符映射为一些数字,问有多少对和这个字符串长度相同的字符串逐位AND得到仍能得到字符串s

    思路:看每位有多少种可能,再把他们相乘并取模,就是答案,注意到最多只有64个字符,所以O(n*n)暴力,4096*1e5大概在4e8可以在一秒内跑完

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int amn=1e5+5,mod=1e9+7;
     4 char a[amn];
     5 int main(){
     6     ios::sync_with_stdio(0);
     7     cin>>a;
     8     long long ans=1,sum;
     9     int len=strlen(a),in,jg;
    10     for(int i=0;i<len;i++){
    11         if(a[i]>='0'&&a[i]<='9')in=a[i]-'0';
    12         else if(a[i]>='A'&&a[i]<='Z')in=a[i]-'A'+10;
    13         else if(a[i]>='a'&&a[i]<='z')in=a[i]-'a'+36;
    14         else if(a[i]=='-')in=62;
    15         else in=63;
    16         sum=0;
    17         for(int j=0;j<=63;j++){
    18             for(int k=0;k<=63;k++){
    19                 jg=j&k;
    20                 if(jg==in)sum++;
    21             }
    22         }
    23         ans=((ans%mod)*(sum%mod))%mod;
    24     }
    25     printf("%lld
    ",ans);
    26 }
    27 /***
    28 给你一个字符串s,把字符映射为一些数字,问有多少对和这个字符串长度相同的字符串逐位AND得到仍能得到字符串s
    29 看每位有多少种可能,再把他们相乘并取模,就是答案,注意到最多只有64个字符,所以O(n*n)暴力,4096*1e5大概在4e8可以在一秒内跑完
    30 ***/
  • 相关阅读:
    shell去重
    JDBC源码解析
    try catch finally
    URL
    域名与IP地址的联系与区别
    C++stack
    C++vector
    单链表常见面试题(C语言实现)
    数据库limit子句
    strcpy和memcpy的区别
  • 原文地址:https://www.cnblogs.com/Railgun000/p/11310872.html
Copyright © 2011-2022 走看看