【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑)

题干:

Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to find their quantity modulo 1000000007 (109 + 7). Be careful and don't miss a string or two!

Let us remind you that a string is a palindrome if it can be read the same way in either direction, from the left to the right and from the right to the left.

Input

The first and only line contains three integers: nm and k (1 ≤ n, m, k ≤ 2000).

Output

Print a single integer — the number of strings of the described type modulo 1000000007 (109 + 7).

Examples

Input

1 1 1

Output

1

Input

5 2 4

Output

2

Note

In the first sample only one string is valid: "a" (let's denote the only letter of our alphabet as "a").

In the second sample (if we denote the alphabet letters as "a" and "b") the following strings are valid: "aaaaa" and "bbbbb".

题目大意:

定义一种字符串:长度为n,最多由m种字符组成,且其中任意长度为k的子串必须是回文串。那么这样的串你能构造出多少个呢?这个数可能很大,所以结果必须mod1000000007,小心不要遗漏任何字符串。

解题报告:

   分成几种情况考虑一下就好了、、、

   首先要明确回文串这东西奇数个数和偶数个数显然要分开讨论的、、所以我们分k的奇偶,n是总长度肯定也要考虑,m是字符种类数,,只是用来计算答案的,,所以就不需要对m进行分类讨论了、、

   不过n>k的情况是真的坑啊,,这种情况不应该输出0吗????

AC代码:

#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
const int mod = 1000000007;
ll quick(ll a,ll k) {ll res = 1;while(k) {if(k&1) res = (res*a)%mod;k>>=1;a=(a*a)%mod;}return res;
}
int main()
{ll n,m,k;scanf("%lld%lld%lld",&n,&m,&k);if(k>n) {printf("%lld\n",quick(m,n));return 0;} else if(k==n) {printf("%lld\n",quick(m,(n+1)/2));return 0;}if(k==1) {printf("%lld\n",quick(m,n));return 0;}if(k%2==0) {printf("%lld\n",m);} else {printf("%lld\n",quick(m,2));}return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441147.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2008r装mysql_mysql5.7.17在win2008R2的64位系统安装与配置实例

安装MySql操作系统&#xff1a;Windows Server 2008 R2 StandardMySql版本&#xff1a;mysql-5.7.17-winx64第一步&#xff1a;解压mysql-5.7.17-winx64.zip到指定位置第二步&#xff1a;安装文件根目录下添加data文件夹&#xff0c;将my-default.ini重命名为my.ini第三步&…

【POJ - 2377】Bad Cowtractors (最大生成树,并查集)

题干&#xff1a; Bessie has been hired to build a cheap internet network among Farmer Johns N (2 < N < 1,000) barns that are conveniently numbered 1..N. FJ has already done some surveying, and found M (1 < M < 20,000) possible connection route…

csv转为utf8编码_读取UTF8编码的CSV并转换为UTF-16

我正在读取具有UTF8编码的CSV文件&#xff1a;ifile open(fname, "r")for row in csv.reader(ifile):name row[0]print repr(row[0])这很好用&#xff0c;并打印出我希望它打印出来的东西; UTF8编码 str &#xff1a;> \xc3\x81lvaro Salazar> \xc3\x89lodie…

【 CodeForces - 799A 】Carrot Cakes(模拟,细节,有坑)

题干&#xff1a; In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently dont have any. H…

mysql 递归实现树形_Mysql实现树形递归查询

最近在做项目迁移&#xff0c;Oracle版本的迁到Mysql版本&#xff0c;遇到有些oracle的函数&#xff0c;mysql并没有&#xff0c;所以就只好想自定义函数或者找到替换函数的方法进行改造。Oracle递归查询oracle实现递归查询的话&#xff0c;就可以使用start with ... connect b…

【CH - 1401】 兔子与兔子(字符串哈希)

题干&#xff1a; 描述 很久很久以前&#xff0c;森林里住着一群兔子。有一天&#xff0c;兔子们想要研究自己的 DNA 序列。我们首先选取一个好长好长的 DNA 序列&#xff08;小兔子是外星生物&#xff0c;DNA 序列可能包含 26 个小写英文字母&#xff09;&#xff0c;然后我…

postmain请求中午乱码_完美解决Get和Post请求中文乱码的问题

对于Post请求&#xff0c;只需在Servlet或者jsp中写入如下代码就可以把解决从表单中传入的中文乱码问题request.setCharacterEncoding("utf-8");而对于Get请求&#xff0c;因为请求参数会被附加到地址栏的URL之后&#xff0c;所以不能用上面的处理方法。应该这样&…

【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)

题干&#xff1a; 2018百度之星复赛晋级名单出炉&#xff08;增加20%晋级名额&#xff09;~ zhxs contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 3779 Accepted Submission(s): 1226 Problem Desc…

python批量打印word_Python使用扩展库pywin32实现批量文档打印实例

本文代码需要正确安装Python扩展库pywin32&#xff0c;建议下载whl文件进行离线安装。然后调用win32api的ShellExecute()函数来实现文档打印&#xff0c;系统会根据文档类型自动选择不同的软件进行打开并自动打印&#xff0c;如果要打印的是图片的话&#xff0c;需要手工确认一…

【牛客 - 283E】贪心只能过样例(模拟)

题干&#xff1a; 小西是单身狗&#xff0c;所以她不喜欢看到有CP在秀恩爱&#xff01; 有一天&#xff0c;小西出来闲逛&#xff0c;发现街上的行人都排成了一排&#xff0c;并且可以用这种形式表示&#xff1a; MMFMMFFFMMM 其中M表示男孩子&#xff0c;F表示女装的男孩…

apmserver导入MySQL_mysql数据库导入导出

window下1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql2.导出一个表mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名mysqldump -u dbuser -p dbname users> dbname_users.sql3.导出一个数据库结…

【牛客 - 283C】模拟只会猜题意(简单模拟)

题干&#xff1a; 小西突然觉得回文串是一种非常优雅的东西&#xff0c;她突然想要把身边所有的字符串都变成回文&#xff01; 所谓回文串就是一个倒置后仍与自身相等的字符串&#xff0c;如“gxuacmmcauxg”和“gxuacmcauxg”。 小西不喜欢单身狗&#xff0c;所以小西只会…

sql开启mysql远程连接_SQLServer2008设置开启远程连接

SQLServer2008设置开启INTERNET远程连接 SQL Server 2008默认是不允许远程连接的&#xff0c;sa帐户默认禁用的&#xff0c;如果想要在本地用SSMS连接远程服务器上的SQL Server 2008&#xff0c;需要做两个部分的配置&#xff1a; 使用sa账户登录SQL Server Management Studio(…

【牛客 - 283H】图论一顿套模板(思维转化,Dijkstra)

题干&#xff1a; 由于临近广西大学建校90周年校庆&#xff0c;西大开始了喜闻乐见的校园修缮工程&#xff01; 然后问题出现了&#xff0c;西大内部有许许多多的道路&#xff0c;据统计有N栋楼和M条道路&#xff08;单向&#xff09;&#xff0c;每条路都有“不整洁度”W&…

spss相关性分析看结果_spss相关性分析

当我们想要了解变量的相关程度时,就需要用到相关分析,而相关分析也是回归之前很重要的一步,通常用到的方法是pearson方法。 首先解释一下相关系数,相关系数反应的是两个变量之间变化趋势的方向以及程度,其值范围为-1到+1,正值表示正相关,负值表示负相关,绝对值越大表示…

【牛客 - 283F】出装方案(最小费用最大流)

题干&#xff1a; 众所周知&#xff0c;在各种对抗类游戏里装备都是很重要的一环&#xff0c;不同的出装方案会给玩家带来不同的强度。 dalao手里有N件装备&#xff0c;现在dalao要把装备分给N个队友&#xff0c;每个队友只能分一件装备&#xff0c;而每个队友穿上不同的装…

mysql瓶颈分析_网站瓶颈分析—MYSQL性能分析

一、关于慢查询设置和分析查找慢查询参数mysql> show variables like long%;---------------------------| Variable_name | Value |---------------------------| long_query_time | 10.000000 |---------------------------mysql> show variables like slow%;---------…

【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

题干&#xff1a; Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the strings length e…

【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

题干&#xff1a; Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Po…

离散信号的抽取和内插例题_《数字信号处理》学习指导与题解 2011年版

《数字信号处理》学习指导与题解出版时间&#xff1a;2011年版内容简介《〈数字信号处理〉学习指导与题解》对“数字信号处理”教学大纲要求的所有知识点进行了提纲挈领的阐述&#xff0c;对于教材《数字信号处理》(吴瑛等主编&#xff0c;2009年8月由西安电子科技大学 出版发行…