日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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:?n,?m?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的子串必須是回文串。那么這樣的串你能構(gòu)造出多少個呢?這個數(shù)可能很大,所以結(jié)果必須mod1000000007,小心不要遺漏任何字符串。

解題報告:

? ?分成幾種情況考慮一下就好了、、、

? ?首先要明確回文串這東西奇數(shù)個數(shù)和偶數(shù)個數(shù)顯然要分開討論的、、所以我們分k的奇偶,n是總長度肯定也要考慮,m是字符種類數(shù),,只是用來計算答案的,,所以就不需要對m進行分類討論了、、

? ?不過n>k的情況是真的坑啊,,這種情況不應(yīng)該輸出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 ;}

?

總結(jié)

以上是生活随笔為你收集整理的【CodeForces - 151D】Quantity of Strings (字符串问题,思维推导,有坑)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。