codeforces 677C C. Vanya and Label(组合数学+快速幂)
题目链接:
1 second
256 megabytes
standard input
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.
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
- 题意:
- 每一位用这些字符来代替,问有多少对与s相同长度的字符串的&运算之后等于s;
- 思路:
- 把这些字符转化成数字后变成2进制,看有多少个0,如果有n个0,那么就是3的n次方;
因为每一个为0的位置上可以有0&1,1&0,0&0,这3种情况,最后结果就是3的n次方了,快速幂;- AC代码:
- #include <bits/stdc++.h>
- /*#include <vector>
- #include <iostream>
- #include <queue>
- #include <cmath>
- #include <map>
- #include <cstring>
- #include <algorithm>
- #include <cstdio>
- */
- using namespace std;
- #define Riep(n) for(int i=1;i<=n;i++)
- #define Riop(n) for(int i=0;i<n;i++)
- #define Rjep(n) for(int j=1;j<=n;j++)
- #define Rjop(n) for(int j=0;j<n;j++)
- #define mst(ss,b) memset(ss,b,sizeof(ss));
- typedef long long LL;
- template<class T> void read(T&num) {
- char CH; bool F=false;
- for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
- for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
- F && (num=-num);
- }
- int stk[], tp;
- template<class T> inline void print(T p) {
- if(!p) { puts(""); return; }
- while(p) stk[++ tp] = p%, p/=;
- while(tp) putchar(stk[tp--] + '');
- putchar('\n');
- }
- const LL mod=1e9+;
- const double PI=acos(-1.0);
- const LL inf=1e10;
- const int N=1e5+;
- char s[N];
- int check(int x)
- {
- if(s[x]>=''&&s[x]<='')return s[x]-'';
- else if(s[x]>='a'&&s[x]<='z')return s[x]-'a'+;
- else if(s[x]>='A'&&s[x]<='Z')return s[x]-'A'+;
- else if(s[x]=='-')return ;
- else if(s[x]=='_')return ;
- }
- int fun(int x)
- {
- int num=;
- int cnt=;
- while(cnt--)
- {
- if(x%==)num++;
- x=(x>>);
- }
- return num;
- }
- LL fastpow(int y)
- {
- LL ans=,base=;
- while(y)
- {
- if(y&)
- {
- ans=ans*base;
- ans%=mod;
- }
- base=base*base;
- base%=mod;
- y=(y>>);
- }
- return ans;
- }
- int main()
- {
- scanf("%s",s);
- int len=strlen(s);
- int sum=;
- for(int i=;i<len;i++)
- {
- int x=check(i);
- sum=sum+fun(x);
- }
- print(fastpow(sum));
- return ;
- }
codeforces 677C C. Vanya and Label(组合数学+快速幂)的更多相关文章
- 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} ...
- CodeForces - 598A Tricky Sum (数学,快速幂的运用)
传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memor ...
- hdu 5363 组合数学 快速幂
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...
- UVA 11609 Teams 组合数学+快速幂
In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...
- BZOJ_1008_[HNOI2008]_越狱_(简单组合数学+快速幂)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1008 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰 ...
- Codeforces 514E Darth Vader and Tree 矩阵快速幂
Darth Vader and Tree 感觉是个很裸的矩阵快速幂, 搞个100 × 100 的矩阵, 直接转移就好啦. #include<bits/stdc++.h> #define L ...
- Codeforces 576D Flights for Regular Customers 矩阵快速幂+DP
题意: 给一个$n$点$m$边的连通图 每个边有一个权值$d$ 当且仅当当前走过的步数$\ge d$时 才可以走这条边 问从节点$1$到节点$n$的最短路 好神的一道题 直接写做法喽 首先我们对边按$ ...
- CodeForces 450B Jzzhu and Sequences(矩阵快速幂)题解
思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)= ...
- 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- ...
随机推荐
- 在jybot下跑Selenium2Library
应用场景:项目组要将原有SeleniumLibrary写的脚本切换到Selenium2Library(后称S2L)下,但是原来有很多Java写的库,综合考虑认为还是在Jython下跑比较合适.但是安装 ...
- Java日期格式化
翻译人员: 铁锚 翻译时间: 2013年11月17日 原文链接: Simple example to show how to use Date Formatting in Java 代码示例如下, ...
- mybatis 注解快速上手
一.mybatis 简单注解 关键注解词 : @Insert : 插入sql , 和xml insert sql语法完全一样 @Select : 查询sql, 和xml select sql语法完全一 ...
- Tomcat创建虚拟目录和程序热部署
虚拟目录的设置 方法一:在${tomcat安装目录}/conf/Catalina/localhost目录下添加与web应用同名的xml配置文件,这里站点名称为test为例子. test.xml内容:& ...
- windows的iis做后门,隐藏访问,无日志<转>
windows下的iis5/iis6做后门,隐藏访问,不留访问记录或者不留日志 好不容易攻下一台Windows2000/2003 IIS服务器,你一定会想,怎样才能长期占有这个“肉鸡”呢?聪明的你肯定 ...
- Qt技巧:QProcess与外部程序的调用
项目做到一定阶段,常常须要在原来的project上调用外部程序. Qt为此提供了QProcess类,QProcess可用于完毕启动外部程序,并与之交互通信. 一.启动外部程序的两种方式: (1)一体式 ...
- MySQL Profile
1:查看MySQL当前版本是否支持profile mysql> SELECT @@HAVE_PROFILING; +------------------+ | @@HAVE_PROFILING ...
- jquery的匿名函数研究
jQuery片段: ? 1 2 3 ( function (){ //这里忽略jQuery所有实现 })(); 半年前初次接触jQuery的时候,我也像其他人一样很兴奋地想看看源码是什么样的.然而,在 ...
- Codeforces Gym 100015C City Driving 离线LCA
City Driving 题目连接: http://codeforces.com/gym/100015/attachments Description You recently started fre ...
- 使用.net(C#)发送邮件学习手册(带成功案例)
使用.net(C#)发送邮件学习手册(带成功案例) 1.了解发送邮件的三种方式 2.实例介绍使用client.DeliveryMethod = System.Net.Mail.SmtpDelivery ...