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的隧道,人和车轮流走,人先向右走一步,然后选在是在原地不动还是上下移动一格,之后车开 ...
随机推荐
- 假如m是奇数,且m>=3,证明m(m² -1)能被8整除
m是奇数,且m>=3 =>m可以用表达式2n-1,n>=2 =>m²-1 = (2n-1)²-1 =>m²-1 = 4n²-4n+1-1 =>m²-1 = 4n²- ...
- GetRelativePath获取相对路径
public static string GetRelativePath(string baseDirPath, string subFullPath) { // ForceBasePath to a ...
- AutoIt上传非input控件方式的文件脚本
AutoIt目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作.它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现自动 ...
- mysql数据库备份/恢复
备份数据库(进入Mysql bin目录下/C:\Program Files\MySQL\MySQL Server 5.6\bin)本地安装mysql数据库 备份表结构及数据 mysqldump -hl ...
- CF Gym 100187B A Lot of Joy (古典概型)
题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少? 题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另 ...
- 【转】 iOS学习之NSBundle介绍和使用
bundle是一个目录,其中包含了程序会使用到的资源.这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in).对应bundle, cocoa提供了类NSBun ...
- Paper: TranE
论文标题:Translating Embeddings for Modeling Multi-relational Data 标题翻译:多元关系数据翻译嵌入建模 摘要: 考虑多元关系数据的实体和关系在 ...
- tomcat - CPU高占用问题记录
先查询进程 top 再根据进程号,查出进程的线程 ps p 3036 -L -o pcpu,pid,tid,time,tname,cmd 得到最高使用率CPU的线程TID,转换成16进制 printf ...
- css实现页面文字不换行、自动换行、强制换行
强制不换行 div{ white-space:nowrap; } 自动换行 div{ word-wrap: break-word; word-break: normal; } 强制英文单词断行 div ...
- 【Kafka】搭建和测试等问题
1.安装启动kafka #跳转到下载目录cd /opt/setup # 下载安装包 wget http://mirror.bit.edu.cn/apache/kafka/0.10.2.0/kafka_ ...