CodeForces 150B- Quantity of Strings 推算..
假设 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 推算..的更多相关文章
- Codeforces 385B Bear and Strings
题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. ...
- Codeforces 482C Game with Strings(dp+概率)
题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,如今从中选定一个字符串为答案串,你不知道答案串是哪个.可是能够通过询问来确定, 每次询问一个位置 ...
- Codeforces Round #107 (Div. 1) B. Quantity of Strings(推算)
http://codeforces.com/problemset/problem/150/B 题意: 给出n,m,k,n表示字符串的长度为n,m表示字符种类个数,k表示每k个数都必须是回文串,求满足要 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 682D Alyona and Strings (四维DP)
Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...
- codeforces 518A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces 149 E. Martian Strings
正反两遍扩展KMP,维护公共长度为L时.出如今最左边和最右边的位置. . .. 然后枚举推断... E. Martian Strings time limit per test 2 seconds m ...
- Codeforces 985 F - Isomorphic Strings
F - Isomorphic Strings 思路:字符串hash 对于每一个字母单独hash 对于一段区间,求出每个字母的hash值,然后排序,如果能匹配上,就说明在这段区间存在字母间的一一映射 代 ...
- CodeForces - 616F:Expensive Strings (后缀自动机)
You are given n strings ti. Each string has cost ci. Let's define the function of string , where ps, ...
随机推荐
- C++ template学习二 类模板定义及实例化
一个类模板(也称为类属类或类生成类)允许用户为类定义一种模式,使得类中的某些数据成员.默写成员函数的参数.某些成员函数的返回值,能够取任意类型(包括系统预定义的和用户自定义的). 如果一个类中数据成员 ...
- ROS的文件系统
这篇博客介绍一下ROS的文件系统的基本概念,用户可以直接在官方网站:http://wiki.ros.org/ROS/Tutorials/NavigatingTheFilesystem去查看官方手册. ...
- leetcode Palindrome Number python
class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool &quo ...
- linux杂记(?)命令别名——alias
linux中的命令别名--alias linux中的命令别名--alias 1. 用命令alias可以查询系统中有哪些可用的命令别名 2.添加命令别名 回车查看, 别名建立成功 3.查询命令的地址ty ...
- JS笔记 入门第二
输出内容 document.write(); alert("hello!"); alert(mynum); </script> 注:alert弹出消息对话框(包含一个确 ...
- scanf(),gets(),gechar()函数小结
1. 使用scanf()函数从终端输入字符串时,刚开始输入的所有空格不计入当前字符串,以 space,enter,tab键结束当前字符串的输入:最后的space,enter,tab字符会留在输入缓冲区 ...
- Linux 网络编程基础(3) -- 数据的IO
首先介绍两个数据结构及相关的操作函数:struct iovec.struct msghdr struct iovec { void * iov_base; /*向量的缓冲地址*/ size_t ...
- ie7(z-index)
父级元素加上position:relative;并设置z-index. 父级元素的z-index优先,子元素的z-index是相对于父级元素的index. <div style="po ...
- CCNA实验(9) -- Frame Relay
帧中继的一些特点:1.中小企业常用的广域网线路2.通信费用较低3.配置较为复杂 1.将Cisco路由器配置为帧中继交换机2.帧中继基本配置.帧中继映射3.在帧中继的链路上运行RIPv24.帧中继的多点 ...
- js 触摸事件
js触摸事件 应用在移动端 webkit内核都支持. 触摸事件api https://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html 事件 ...