假设 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:

  1. #include<iostream>
  2. #include<stack>
  3. #include<queue>
  4. #include<stdio.h>
  5. #include<algorithm>
  6. #include<string.h>
  7. #include<cmath>
  8. #define ll long long
  9. #define oo 1000000007
  10. #define MAXN 100005
  11. using namespace std;
  12. int n,m,k;
  13. int POW(ll m,ll n)
  14. {
  15. int i;
  16. ll ans=1;
  17. for (i=1;i<=n;i++) ans=(ans*m)%oo;
  18. return (int)ans;
  19. }
  20. int main()
  21. {
  22. while (~scanf("%d%d%d",&n,&m,&k))
  23. {
  24. if (k>n || k==1) printf("%d\n",POW(m,n));
  25. else
  26. if (k==n) printf("%d\n",POW(m,(k+1)/2));
  27. else
  28. if (k%2) printf("%d\n",m*m);
  29. else
  30. printf("%d\n",m);
  31. }
  32. return 0;
  33. }

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. 如何为你的美术妹子做Unity的小工具(一)

    在上的工具栏添加   也就是这个位置

  2. Linux平台下使用rman进行oracle数据库迁移

        实验目的:将oracle数据库从一台机器迁移到另外的一台机器(同为linux平台),设置为不同的路径,不同的实例名 源端: ORACLE_BASE=/u01/app/oracle ORACLE ...

  3. 五年26个版本:Linux系统内核全程回顾

    Phoronix.com今天将他们对Linux系统的研究发挥到了极致:从2005年年中的2.6.12,到正在开发中的2.6.37,五年多来的26个Linux内核版本来了个“群英荟萃”! 完成如此庞大规 ...

  4. 转: Promises与Javascript异步编程

    在如今都追求用户体验的时代,Ajax应用真的是无所不在.加上这些年浏览器技术.HTML5以及CSS3等的发展,越来越多的富Web应用出现:在给与我们良好体验的同时,Web开发人员在背后需要处理越来越多 ...

  5. axis1客户端调用webservice的通用代码

    1.axis1 作为web service 客户端时,调用web service 服务端的通用代码 String url = "http://www.webxml.com.cn/webser ...

  6. PHP下通过file_get_contents\curl的方法实现获取远程网页内容(别忘了还有PhpRPC)

    [php]PHP中file_get_contents()与file_put_contents()函数细节详解 php函数file_get_contents(一) 案例: 早在2010年时候遇到过这样的 ...

  7. linux date -d 的一些使用方法

    date命令中格式输出类型字符含义例如以下: %% 一个文字的 % %a 当前locale 的星期名缩写(比如: 日,代表星期日) %A 当前locale 的星期名全称 (如:星期日) %b 当前lo ...

  8. Android应用开发基础篇(2)-----Notification(状态栏通知)

    一.概述      Notification这个部件的功能是在状态栏里显示消息提醒,比如有未读的短信或者是未接的电话,那么状态栏里都会有显示,更或者是从某个应用(比如QQ,酷我音乐等等)里按Home键 ...

  9. 在MySQL中创建实现自增的序列(Sequence)的教程

    这篇文章主要介绍了在MySQL中创建实现自增的序列(Sequence)的教程,分别列举了两个实例并简单讨论了一些限制因素,需要的朋友可以参考下 项目应用中,曾有以下一个场景: 接口中要求发送一个int ...

  10. activity的横屏和竖屏设置

    主要在清单文件这样配置: <application android:allowBackup="true" android:icon="@drawable/ic_la ...