Mutual Training for Wannafly Union #8 D - Mr.BG Hates Palindrome 取余
Mr.BG is very busy person. So you have been given enough time (1000 milliseconds) to help him.
Mr. BG has a bag of marbles with different alphabets written on them. And he has become busy on playing with these marbles by putting them in N boxes placed in a row. There are exactly M distinct type of marbles, N of each type.
Now he puts only N marbles (out of M*N) in N boxes, one by one and upon completion he writes down the letters on the marbles on a paper to form a string. As Mr.BG hates palindrome strings (strings which read same from both sides e.g. MADAM), he erases palindrome string from the paper as soon as he finds one.
Now he is wondering how many different strings he might get on his paper if he could try all possible combination of putting the marbles in the boxes. So you have to help him by answering. As there could be many strings so print it modulo 1,000,000,007.
Input
Input starts with an integer TC(<=10), denoting the number of test cases. Each case starts with two non negative integers N(<=100000) and M(<=26) as described above.
Output
For each case, print the case number and total number of strings written on the paper modulo 1000000007.
Example
Input:
2
2 2
2 3
Output:
Case 1: 2
Case 2: 6
大佬给我们讲的题解,一句带过,我现在还不是很清楚那个公式是怎么来的,先标记下这个题目,m的n方-m的(n+1)/2次方,然后就是大数取余了,wa了一次,因为取余会出现负数,所以要先加上mod
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL po(LL n,LL m){
LL s=m%mod;
for(LL i=1;i<n;i++)
s=(s*m)%mod;
return s;}
int main(){
int t,k=1;
scanf("%d",&t);
while(t--){
LL n,m;
scanf("%lld%lld",&n,&m);
printf("Case %d: %lld\n",k++,(po(n,m)-po((n+1)/2,m)+mod)%mod);
}
return 0;
}
Mutual Training for Wannafly Union #8 D - Mr.BG Hates Palindrome 取余的更多相关文章
- 【Mutual Training for Wannafly Union #1 】
A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...
- Mutual Training for Wannafly Union #1解题报告
---恢复内容开始--- q神等人组织的vjudge上的多校训练,题目基本上都来自于CF,#1是上周进行的,参加后感觉收获很多,因为上周准备期中比较忙,解题报告现在补上. 比赛地址(兼题目地址) A题 ...
- Mutual Training for Wannafly Union #6 E - Summer Trip(并查集)
题目链接:http://www.spoj.com/problems/IAPCR2F/en/ 题目大意: 给m个数字代表的大小,之后n组数据,两两关联,关联后的所有数字为一组,从小到大输出组数以及对应的 ...
- Mutual Training for Wannafly Union #2
codeforces 298A. Snow Footprints 分类讨论三种情况: ①..RRRRRR… ②..LLLLLLL… ③..RRRLLLL.. //AC by lwq: #includ ...
- Mutual Training for Wannafly Union #9
A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成 ...
- Mutual Training for Wannafly Union #6
A =w= B QvQ C 题意:有长度为n的序列(n<=5e5),求满足条件的a,b,c,d的组数,要求满足条件:min([a,b])<=min([c,d]),a<=b<c& ...
- Mutual Training for Wannafly Union #5
A(UVA12336) 题意:给一个n*m(n,m<=1e5)的棋盘,棋盘上有一些障碍点不能放棋子,现在要在棋盘上放4个棋子,满足A->B->C->D->A,其中走的规则 ...
- Wannafly Union Goodbye 2016
A 题意:平面上有n个点(n<=100000),给你一个p(20<=p<=100) 判断是否存在一条直线至少过[np/100](向上取整)个点,时限20s,多组数据 分析:概率算法 ...
- Wannafly Union#1
题目链接:http://vjudge.net/contest/142053#overview A.题意:有一个3*n的隧道,人和车轮流走,人先向右走一步,然后选在是在原地不动还是上下移动一格,之后车开 ...
随机推荐
- pytest+allure2+jenkins环境部署
1.pycharm安装allure-pytest 2.jenkins -> 系统管理 -> 插件管理 -> 可选插件中过滤Allure,勾选对应插件安装 如下图: 3.安装完插件后 ...
- python_89_configparser模块
用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser.在python2.x版本中为ConfigPsresr 来看一个好多软件的常见文档格式如下 [ ...
- 解决cocos2dx 3.x 导入cocostudio的ui界面出现错位问题
笔者今天发现导入cocostudio的ui界面时,会有部分控件出现错位的现象,后来我看了一下源码,发现是部分控件是没有继承 Layout类,导致不能设置控件位置造成,原因可以看看cocos2dx 源码 ...
- [vijos]P1979 NOIP2015 信息传递
描述 有 n 个同学(编号为 1 到 n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 TiTi 的同学. 游戏开始时,每人都只知道 ...
- Postgres-XL的限制
Postgres-XL是基于PostgreSQL的一个分布式数据库. 相比于PostgreSQL,XL的表的数据是可以分布到不同的datanode上的,对存在于不同的datanode上的数据进行处理, ...
- Mycat高可用解决方案二(主从复制)
Mycat高可用解决方案二(主从复制) 系统部署规划 名称 IP 主机名称 用户名/密码 配置 mysql主节点 192.168.199.110 mysql-01 root/hadoop 2核/2G ...
- 使用apache benchmark(ab) 测试报错: apr_socket_recv: Connection timed out (110)
使用ab( apache benchmark )测试的时候,使用如下命令: ab -n 15000 -c 200 http://localhost/abc/abc.php 执行操作一定条数,或连续 ...
- 【linux】【磁盘分割】Linux磁盘分割
全部的磁盘阵列容量均给/cluster/raid目录,占有2TB的容量: 2 GB的swap容量: 分割出/, /usr, /var, /tmp等目录,避免程序错误造成系统的困扰: /home也独立出 ...
- 04 Django模板
基本概念 作为Web框架,Django提供了模板,用于编写html代码,还可以嵌入模板代码更快更方便的完成页面开发,再通过在视图中渲染模板,将生成最终的html字符串返回给客户端浏览器 模版致力于表达 ...
- R-data.table
data.table可以扩展和增强data.frame的功能,在分组操作和组合时访问速度更快. require(data.table) theDT = data.table(A=1:10, B=let ...