假设 k = 5 , n>k ,   (1,2,3,4,5)  -> 1=5,2=4,3任意

(2,3,4,5,6) -> 2=6,3=5,4任意...综合上面的可得出1=3=5,2=4=6

(3,4,5,6,7) -> 3=7,4=6,5任意...综合上面的可得出1=3=5=7,2=4=6

.......                 综上可得..奇数位的数应该相同,偶数位的数应该相同

再假设k = 4,   n>k     (1,2,3,4) - >1=4,2=3

(2,3,4,5) - > 2=5,3=4...综合上面的可得出1=2=3=4=5

(3,4,5,6) -> 3=6,4=5...综合上面的可得出 1=2=3=4=5=6

.......                  综上所得..所有的数必须相同

大致的思路有了...但是要注意几个特殊的情况.. 这些情况的造成是因为没有有交集的回文串..不能上下综合得出条件..

例如...k=1的时候..回文串都是独立的....总数是m^n

k=n的时候..回文串只有一个..当然也是独立的...总数是m^((n+1)/2)

k>n的时候...串可以任意了.m^n....我觉得这个数据有些无聊..

Program:

#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#define ll long long
#define oo 1000000007
#define MAXN 100005
using namespace std;
int n,m,k;
int POW(ll m,ll n)
{
int i;
ll ans=1;
for (i=1;i<=n;i++) ans=(ans*m)%oo;
return (int)ans;
}
int main()
{
while (~scanf("%d%d%d",&n,&m,&k))
{
if (k>n || k==1) printf("%d\n",POW(m,n));
else
if (k==n) printf("%d\n",POW(m,(k+1)/2));
else
if (k%2) printf("%d\n",m*m);
else
printf("%d\n",m);
}
return 0;
}

CodeForces 150B- Quantity of Strings 推算..的更多相关文章

  1. Codeforces 385B Bear and Strings

    题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...

  2. Codeforces 482C Game with Strings(dp+概率)

    题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...

  3. Codeforces Round #107 (Div. 1) B. Quantity of Strings(推算)

    http://codeforces.com/problemset/problem/150/B 题意: 给出n,m,k,n表示字符串的长度为n,m表示字符种类个数,k表示每k个数都必须是回文串,求满足要 ...

  4. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. CodeForces 682D Alyona and Strings (四维DP)

    Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...

  6. codeforces 518A. Vitaly and Strings

    A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Codeforces 149 E. Martian Strings

    正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...

  8. Codeforces 985 F - Isomorphic Strings

    F - Isomorphic Strings 思路:字符串hash 对于每一个字母单独hash 对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射 代 ...

  9. CodeForces - 616F:Expensive Strings (后缀自动机)

    You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, ...

随机推荐

  1. cocos2d-x学习日志(12) --弹出对话框的设计与实现

    我们时常需要这么些功能,弹出一个层,给与用户一些提示,这也是一种模态窗口,在没有对当前对话框进行确认的时候,不能继续往下操作. 功能分析 我们设计一个对话框,对话框上有几个按钮(个数可定制),当然有个 ...

  2. 保存属性至xml并读取

    import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...

  3. Ubuntu Server修改IP、DNS、hosts

    本文记录下Ubuntu Server 16.04修改IP.DNS.hosts的方法 -------- 1. Ubuntu Server 修改IP sudo vi /etc/network/interf ...

  4. codeblock编译Object-C

    http://blog.csdn.net/ldl22847/article/details/7482971 http://www.cnblogs.com/qingyuan/p/3524791.html ...

  5. ZOJ 3741 Eternal Reality

    Eternal Reality Time Limit: 2 Seconds                                      Memory Limit: 65536 KB In ...

  6. MacOS copy图标shell脚本

    不会shell  同学做的... 可以看见在当前文件夹下创建了一个icons文件夹 最后还压缩了文件夹 #!/bin/bash # readPlist [plist] [key] function r ...

  7. delphi调用外部程序打开文件

    delphi调用外部程序打开文件 ShellExecute的各种用法 一.利用系统默认的邮件收发器发送电子邮件 Uses ..., ShellAPI; Var lpHwnd: HWND; lpOper ...

  8. HTML本地存储,localstorg的应用实例

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. <td style="word-break:break-all"> 在html中控制自动换行

    在html中控制自动换行   其实只要在表格控制中添加一句 <td style="word-break:break-all">就搞定了. 其中可能对英文换行可能会分开一 ...

  10. ZOJ 38727(贪心)

    这道题真心坑.越想越远  想的飞起来了. 最后纠结起后缀表达式的定义来了. 题意: 就是给你一个串 ,  让你用最少改动次数来实它变成一个合法的后缀表达式,  改动方式有两种, 一种是直接加入数字或者 ...