题目链接:

C. 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
  1. z
output
  1. 3
input
  1. V_V
output
  1. 9
input
  1. Codeforces
output
  1. 130653412
  2.  
  3. 题意:
  4.  
  5. 每一位用这些字符来代替,问有多少对与s相同长度的字符串的&运算之后等于s;
  6.  
  7. 思路:
  8.  
  9. 把这些字符转化成数字后变成2进制,看有多少个0,如果有n0,那么就是3n次方;
    因为每一个为0的位置上可以有0&1,1&0,0&0,这3种情况,最后结果就是3n次方了,快速幂;
  10.  
  11. AC代码:
  1. #include <bits/stdc++.h>
  2. /*#include <vector>
  3. #include <iostream>
  4. #include <queue>
  5. #include <cmath>
  6. #include <map>
  7. #include <cstring>
  8. #include <algorithm>
  9. #include <cstdio>
  10. */
  11. using namespace std;
  12. #define Riep(n) for(int i=1;i<=n;i++)
  13. #define Riop(n) for(int i=0;i<n;i++)
  14. #define Rjep(n) for(int j=1;j<=n;j++)
  15. #define Rjop(n) for(int j=0;j<n;j++)
  16. #define mst(ss,b) memset(ss,b,sizeof(ss));
  17. typedef long long LL;
  18. template<class T> void read(T&num) {
  19. char CH; bool F=false;
  20. for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
  21. for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
  22. F && (num=-num);
  23. }
  24. int stk[], tp;
  25. template<class T> inline void print(T p) {
  26. if(!p) { puts(""); return; }
  27. while(p) stk[++ tp] = p%, p/=;
  28. while(tp) putchar(stk[tp--] + '');
  29. putchar('\n');
  30. }
  31.  
  32. const LL mod=1e9+;
  33. const double PI=acos(-1.0);
  34. const LL inf=1e10;
  35. const int N=1e5+;
  36. char s[N];
  37. int check(int x)
  38. {
  39. if(s[x]>=''&&s[x]<='')return s[x]-'';
  40. else if(s[x]>='a'&&s[x]<='z')return s[x]-'a'+;
  41. else if(s[x]>='A'&&s[x]<='Z')return s[x]-'A'+;
  42. else if(s[x]=='-')return ;
  43. else if(s[x]=='_')return ;
  44. }
  45. int fun(int x)
  46. {
  47. int num=;
  48. int cnt=;
  49. while(cnt--)
  50. {
  51. if(x%==)num++;
  52. x=(x>>);
  53. }
  54. return num;
  55. }
  56. LL fastpow(int y)
  57. {
  58. LL ans=,base=;
  59. while(y)
  60. {
  61. if(y&)
  62. {
  63. ans=ans*base;
  64. ans%=mod;
  65. }
  66. base=base*base;
  67. base%=mod;
  68. y=(y>>);
  69. }
  70. return ans;
  71. }
  72.  
  73. int main()
  74. {
  75. scanf("%s",s);
  76. int len=strlen(s);
  77. int sum=;
  78. for(int i=;i<len;i++)
  79. {
  80. int x=check(i);
  81. sum=sum+fun(x);
  82. }
  83. print(fastpow(sum));
  84. return ;
  85. }
  1.  
  1.  

codeforces 677C C. Vanya and Label(组合数学+快速幂)的更多相关文章

  1. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

  2. CodeForces - 598A Tricky Sum (数学,快速幂的运用)

    传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...

  3. hdu 5363 组合数学 快速幂

    Time Limit: 2000/1000 MS (Java/Others)   Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...

  4. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  5. BZOJ_1008_[HNOI2008]_越狱_(简单组合数学+快速幂)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1008 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰 ...

  6. Codeforces 514E Darth Vader and Tree 矩阵快速幂

    Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...

  7. Codeforces 576D Flights for Regular Customers 矩阵快速幂+DP

    题意: 给一个$n$点$m$边的连通图 每个边有一个权值$d$ 当且仅当当前走过的步数$\ge d$时 才可以走这条边 问从节点$1$到节点$n$的最短路 好神的一道题 直接写做法喽 首先我们对边按$ ...

  8. CodeForces 450B Jzzhu and Sequences(矩阵快速幂)题解

    思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)= ...

  9. ACM学习历程—SNNUOJ 1116 A Simple Problem(递推 && 逆元 && 组合数学 && 快速幂)(2015陕西省大学生程序设计竞赛K题)

    Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N- ...

随机推荐

  1. 在jybot下跑Selenium2Library

    应用场景:项目组要将原有SeleniumLibrary写的脚本切换到Selenium2Library(后称S2L)下,但是原来有很多Java写的库,综合考虑认为还是在Jython下跑比较合适.但是安装 ...

  2. Java日期格式化

    翻译人员: 铁锚 翻译时间: 2013年11月17日 原文链接:   Simple example to show how to use Date Formatting in Java 代码示例如下, ...

  3. mybatis 注解快速上手

    一.mybatis 简单注解 关键注解词 : @Insert : 插入sql , 和xml insert sql语法完全一样 @Select : 查询sql, 和xml select sql语法完全一 ...

  4. Tomcat创建虚拟目录和程序热部署

    虚拟目录的设置 方法一:在${tomcat安装目录}/conf/Catalina/localhost目录下添加与web应用同名的xml配置文件,这里站点名称为test为例子. test.xml内容:& ...

  5. windows的iis做后门,隐藏访问,无日志<转>

    windows下的iis5/iis6做后门,隐藏访问,不留访问记录或者不留日志 好不容易攻下一台Windows2000/2003 IIS服务器,你一定会想,怎样才能长期占有这个“肉鸡”呢?聪明的你肯定 ...

  6. Qt技巧:QProcess与外部程序的调用

    项目做到一定阶段,常常须要在原来的project上调用外部程序. Qt为此提供了QProcess类,QProcess可用于完毕启动外部程序,并与之交互通信. 一.启动外部程序的两种方式: (1)一体式 ...

  7. MySQL Profile

    1:查看MySQL当前版本是否支持profile mysql> SELECT @@HAVE_PROFILING; +------------------+ | @@HAVE_PROFILING ...

  8. jquery的匿名函数研究

    jQuery片段: ? 1 2 3 ( function (){ //这里忽略jQuery所有实现 })(); 半年前初次接触jQuery的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在 ...

  9. Codeforces Gym 100015C City Driving 离线LCA

    City Driving 题目连接: http://codeforces.com/gym/100015/attachments Description You recently started fre ...

  10. 使用.net(C#)发送邮件学习手册(带成功案例)

    使用.net(C#)发送邮件学习手册(带成功案例) 1.了解发送邮件的三种方式 2.实例介绍使用client.DeliveryMethod = System.Net.Mail.SmtpDelivery ...