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, ...
随机推荐
- VirtualBox扩展磁盘空间
进入VB的安装目录, 输入命令 VBoxManage list hdds获得当前所有虚拟机的uuid 选择需要扩展的磁盘, 输入 VBoxManage modifyhd uuid –resize 81 ...
- Application(basic)----Easyui
一,效果图. 二,源代码. <!DOCTYPE html><html><head> <meta charset="UTF-8"> & ...
- js写的简单轮播图
这个轮播图代码是从网上找来的,专门找了个写法简单的,只是作为一个小练习,大概原理如下: 1.首先是图片切换2.自动播放3.调用自动播放4.移动到容器上边停止播放,离开自动播放5.移动到导航上停止播放, ...
- SQL 简单练习
USE study; SELECT * FROM EMP --查询雇员姓名的最后三个字母 ) FROM EMP ; --查询10部门雇员进入公司的星期数 --1 查询部门30中的所有员工 --2 列出 ...
- Use eplipse to develop Python project
Source: This is the example how to use eclipse and python. http://www.360doc.com/content/15/0206/10/ ...
- poj 3270 置换
poj 置换的应用 黑书原题P248 /** 题意: 给定序列, 将其按升序排列, 每次交换的代价是两个数之和, 问代价最小是多少 思路:1.对于同一个循环节之内的,肯定是最小的与别的交换代价最小 2 ...
- 设置cmd的codepage的方法
设置cmd的codepage的方法 有时候,我们的cmd.exe的codepage和字体等会变化,比如突然由中文变成英文的codepage(因为一些sh程序的干扰). 下面是修正方法: [HKEY_C ...
- 基于KVM建立虚拟机的步骤及总结说明
1.前言 目前正在涉足云计算IaaS工作,虚拟化是IaaS的重要部分,因此这段时间对各个虚拟机化技术和工具进行研究,研究的目的不仅仅是为了会使用这个工具,而是通过研究了解技术的实现机制和原理,即知其然 ...
- Jquery读取URL参数
$(document).ready(function(){ function getQueryString(name) { var reg = new RegExp("(^|&)&q ...
- 关于javascript的沙箱模式以及缓存方法
在javascript函数代码中,经常会不经意出现全局变量,很可能造成对全局对象的污染,由于这种弊端的存在,那么沙箱模式油然而生.沙箱模式又称为沙盒模式.隔离模式.在js中只有函数可以限定变量作用域, ...