假设 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. 常用的Linux操作命令(一)

    ls 目录 mkdir 创建文件夹 vi 新建文件 :w filename 将文章存入指定的文件名filename :wq 保存并退出编辑文件 :q! 强制离开并放弃编辑的文件 cd 切换到目录/ro ...

  2. javaTemplates-学习笔记二

    配置PlayFramework环境 下载jar包[Play with Activator],这一步有点晕是JAVA程序员CMD执行的步骤;运行了jar包下载了很多配置文件什么的,有的资源没有VPN链接 ...

  3. [LeetCode]题解(python):138-Copy List with Random Pointer

    这道题目不是太懂,参考了http://www.cnblogs.com/zuoyuan/p/3745126.html的博客. 题意: A linked list is given such that e ...

  4. (Problem 92)Square digit chains

    A number chain is created by continuously adding the square of the digits in a number to form a new ...

  5. Springmvc+Spring+Hibernate搭建方法及实例

    Springmvc+Spring+Hibernate搭建方法及实例  

  6. flume 日志采集工具

    Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并 ...

  7. Struts 上下文

    Struts  上下文 ActionContext .ServletActionContext 是继承关系  ActionContext  ActionContext context = Action ...

  8. 取得phpcms网站下所有栏目的内容链接

    今天做了一个小功能,就是取得公司网站的所有文章的内容地址,公司网站是用phpcms 做的,感觉还蛮简单的,记录下: <?php $conf['DB_USER'] = 'user'; $conf[ ...

  9. The Linux device model

    /sys和 /dev的疑问 1./dev 下放的是设备文件,是由应用层mknod创建的文件.假设底层驱动对mknod的设备号有相应的驱动,如open等函数.那么应用层open "/dev/* ...

  10. (译)Node.js的 EventEmitter 教程

    原文标题:Node.js EventEmitter Tutorial 原文链接:http://www.hacksparrow.com/node-js-eventemitter-tutorial.htm ...