题干:

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 ;}

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

  1. 【CodeForces - 155C】Hometask (字符串,思维,贪心,熟悉句式)(总结)

    题干: Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the ...

  2. CodeForces - 798B Mike and strings

    B. Mike and strings time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...

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

    题干: Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wa ...

  4. COW(暴力枚举) + 玄神的字符串(思维题) + Duplicate Strings(字符串思维题)

    '只要坚持就会成功--2022.1.22' 1.COW,这道题的大概意思就是求出一个字符串中一共有多少个COW,不要求连续. 思路: 暴力枚举,枚举每一个包含O,看这个O和前后的C,W结合能组成多少个 ...

  5. CodeForces - 985F Isomorphic Strings(字符串哈希)

    题目链接:点击查看 题目大意:首先规定同构字符串,若字符串s和字符串t互为同构字符串,则必须满足: 两个字符串长度相同 s中的字符种类数与t中的字符种类数相同 s中的每一个字母在t中都有对应,且必须是 ...

  6. 【CodeForces - 298C】Parity Game (思维,有坑)

    题干: You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar be ...

  7. Codeforces Round #644 1360H. Binary Median(思维、构造)

    题目描述: time limit per test 2 seconds memory limit per test 256 megabytes Consider all binary strings ...

  8. [LeetCode] Isomorphic Strings - 字符串操作:数组计数字符个数问题

    题目概述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...

  9. codeforces 596E Wilbur and Strings(DFS)

    题目链接 E. Wilbur and Strings time limit per test 3 seconds memory limit per test 256 megabytes input s ...

最新文章

  1. 通宵加班、猝死频发,但仍建议你不要轻易买保险
  2. 从零开始配置MySQL MMM
  3. junit可执行但控制层无法执行_Junit测试时ContextLoader.getCurrentWebApplicationContext()返回空值...
  4. php新窗口打开链接,wordpress如何设置在新窗口打开链接
  5. solution for python can not import local module
  6. python函数type的用意_Python内置函数Type()函数一个有趣的用法
  7. 基于Twemproxy的Redis集群方案
  8. iOS利用cocoapods 和GitHub组件化序Day1
  9. 怎么做Web应用压力测试?
  10. pboc c语言 开发,APDU
  11. 2022 人工智能 AI 应用 top6
  12. python相减函数subs,自定义sympy中函数子类的subs()功能
  13. windows2003 序列号
  14. 中国被黑站点统计系统 2006年9月分析报告
  15. 解决 dpkg: warning: files list file for package ‘x‘ missing 问题
  16. 小程序进度条_【好玩的游戏大全】我的煎饼屋:好玩的摆摊微信小游戏小程序...
  17. 苹果历代产品中的8大亮点设计(上)
  18. 今日头条精准引流技巧,今日头条超简单的引流技巧
  19. webstorm 一次Git使用很卡的处理记录
  20. 【Android】JNI调用(完整版)

热门文章

  1. [CodeForces-1138B] *Circus 解方程|数学
  2. POJ-1384 Piggy-Bank 多重背包变形
  3. Linux以oracle用户登录,Linux_oracle 10G for linux常用命令,首先以Oracle用户登录1、 - phpStudy...
  4. mysql导出数据库对象命令_mysql数据库导出数据(命令)
  5. rs232串口驱动_电脑主板RS232串口硬件设计
  6. 该文件没有与之关联的程序来执行该操作_Liunx tty子系统分析之三 tty字符设备文件操作接口说明...
  7. 注册登录页面代码用js判断是否填入信息_php实现登录功能
  8. 如何根据原理图画封装_常用原理图封装
  9. python 不确定度_python机器学习-chapter2_16
  10. html注册跳转php错误500,页面跳转后提示HTTP 异常 500(Internal Server Error):服务器尝试执行请求时遇到了意外情况...