Code Lock
Code Lock |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) |
Total Submission(s): 255 Accepted Submission(s): 114 |
Problem Description
A lock you use has a code system to be opened instead of a key. The lock contains a sequence of wheels. Each wheel has the 26 letters of the English alphabet 'a' through 'z', in order. If you move a wheel up, the letter it shows changes to the next letter in the English alphabet (if it was showing the last letter 'z', then it changes to 'a').
At each operation, you are only allowed to move some specific subsequence of contiguous wheels up. This has the same effect of moving each of the wheels up within the subsequence. If a lock can change to another after a sequence of operations, we regard them as same lock. Find out how many different locks exist? |
Input
There are several test cases in the input.
Each test case begin with two integers N (1<=N<=10000000) and M (0<=M<=1000) indicating the length of the code system and the number of legal operations. The input terminates by end of file marker. |
Output
For each test case, output the answer mod 1000000007
|
Sample Input
1 1 |
Sample Output
1 |
Author
hanshuai
|
Source
2010 ACM-ICPC Multi-University Training Contest(3)——Host by WHU
|
Recommend
zhouzeyong
|
/*
没有可操作区间的时候是26的n次方,然后多一个可操作区间,就会少26种
每一个不可操作的区间的种类数是26种,就是26^k种答案
*/
#include<bits/stdc++.h>
using namespace std;
const int mod=;
int n,m;
int l,r;
int x,y;
int bin[];
int findx(int x){
int temp=x;
while(x!=bin[x]){
x=bin[x];
}
bin[temp]=x;
return x;
}
int Union(int x,int y){
int fx=findx(x);
int fy=findx(y);
if(fx!=fy){
bin[fy]=fx;
return ;
}else return ;
}
/***********快速幂模板**************/
long long power(int n,int x){
if(x==) return ;
long long t=power(n,x/);
t=t*t%mod;
if(x%==)t=t*n%mod;
return t;
}
/***********快速幂模板**************/
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n+;i++){
bin[i]=i;
}
int ans=;
for(int i=;i<m;i++){
scanf("%d%d",&x,&y);
ans+=Union(x,y+);
}
printf("%d\n",power(,n-ans));
}
}
Code Lock的更多相关文章
- Code Lock[HDU3461]
Code LockTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Subm ...
- HDU 3461 Code Lock(并查集+二分求幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3461 A lock you use has a code system to be opened in ...
- hdu3461 Code Lock
Problem Description A lock you use has a code system to be opened instead of a key. The lock contain ...
- HDU 3461 Code Lock(并查集)
很好的一个题,思想特别6 题意:给你小写字母个数n,每个字母可以向上翻动,例如:d->c,a->z.然后给你m对数(L,R)(L<=R),表示[L,R]之间可以同时向上翻动,且翻动后 ...
- hdu Code Lock
题意是说有N个字母组成的密码锁, 如[wersdfj], 每一位上的字母可以转动, w可转动变成x, z变成a.但是题目规定, 只能同时转动某个区间上的所有字母, 如[1,3], 那么第1到第3个 ...
- HDU 3461 Code Lock(并查集,合并区间,思路太难想了啊)
完全没思路,题目也没看懂,直接参考大牛们的解法. http://www.myexception.cn/program/723825.html 题意是说有N个字母组成的密码锁,如[wersdfj],每一 ...
- hdu 3461 Code Lock(并查集)2010 ACM-ICPC Multi-University Training Contest(3)
想不到这还可以用并查集解,不过后来证明确实可以…… 题意也有些难理解—— 给你一个锁,这个所由n个字母组成,然后这个锁有m个区间,每次可以对一个区间进行操作,并且区间中的所有字母要同时操作.每次操作可 ...
- hdu 3461 Code Lock
http://acm.hdu.edu.cn/showproblem.php?pid=3461 并差集和幂取模 这道题主要是求不可操作区间. #include <cstdio> #inclu ...
- HDU 3461 Code Lock(并查集的应用+高速幂)
* 65536kb,仅仅能开到1.76*10^7大小的数组. 而题目的N取到了10^7.我開始做的时候没注意,用了按秩合并,uset+rank达到了2*10^7所以MLE,所以貌似不能用按秩合并. 事 ...
随机推荐
- .NET Excel导出方法及其常见问题详解
摘要:.NET Excel导出方法及其常见问题详解. 一.Excel导出的实现方法 在.net 程序开发中,对于Excel文件的导出我们一共有三种导出方式: 利用文件输出流进行读写操作 这种方式的导出 ...
- ssh (免密码登录、开启服务)
ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以Unbutun为例.有机器A(192.168.1.155),B(192.168.1.181).现想 ...
- JSP入门 Listener
实现HttpSessionListener 编写一个OnlineUserListener类 package anni; import java.util.List; import javax.serv ...
- bzoj1087 [SCOI2005][状压DP] 互不侵犯King (状压)
在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. Input 只有一行,包含两个数N,K ( 1 ...
- bzoj1968 COMMON 约数研究
Input只有一行一个整数 N(0 < N < 1000000).Output只有一行输出,为整数M,即f(1)到f(N)的累加和.Sample Input 3 Sample Output ...
- 经典算法研究系列:二、Dijkstra 算法初探
July 二零一一年一月 本文主要参考:算法导论 第二版.维基百科. 一.Dijkstra 算法的介绍 Dijkstra 算法,又叫迪科斯彻算法(Dijkstra),算法解决的是有向图中单个源点到 ...
- CentOS7 Redis安装
Redis介绍 1.安装Redis 官方下载地址:http://download.redis.io 使用Linux下载:wget http://download.redis.io/redis-stab ...
- Python自学笔记-lambda函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 匿名函数 通过 ...
- zoj 1081 Points Within (判断点是否在多边形内)
http://blog.csdn.net/zxy_snow/article/details/6339621先保存,搞懂了再来写
- JS判断浏览器类型与版本
在JS中判断浏览器的类型,估计是每个编辑过页面的开发人员都遇到过的问题.在众多的浏览器产品中,IE.Firefox.Opera.Safari........众多品牌却标准不一,因此时常需要根据不同的浏 ...