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, ...
随机推荐
- 菜鸟初试水--JQuery基础
此文仅作入门级文章,望大神们高抬贵手! JQuery: 它是一套跨浏览器的JavaScript库,简化HTML与JavaScript之间的操作. JQuery的用途: ①访问和操作DOM元素: 使用j ...
- BZOJ 3533: [Sdoi2014]向量集( 线段树 + 三分 )
答案一定是在凸壳上的(y>0上凸壳, y<0下凸壳). 线段树维护, 至多N次询问, 每次询问影响O(logN)数量级的线段树结点, 每个结点O(logN)暴力建凸壳, 然后O(logN) ...
- 拔一拔 ExtJS 3.4 里你遇到的没遇到的 BUG(1)
本文从今天开始,我要做的就是不断的更新,不断的披露ExtJS 3.4的BUG并修复它.需要注意的是版本为3.4而不是4.0,因为4.0改动和变化比较大,所以不要对号入座. 嘿嘿,本人不怎么写东西,不过 ...
- Class类对象的三种实例化方法
class X { } public class GetClassDemo01 { public static void main(String[] args) { X x = ...
- 【LeetCode题意分析&解答】36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- MySQL学习系列一---命令行连接mysql和执行sql文件
1.命令行连接mysql #mysql -h(主机) -u(用户名) -p (数据库名) mysql -hlocalhost -uroot -p testdb Enter password: **** ...
- BaaS with Kinvey and Delphi 10.1 Berlin
In this article I will show you how to connect yourdesktop and mobile applications to a mobile backe ...
- POJ 3311 Hie with the Pie (BFS+最短路+状态压缩)
题意:类似于TSP问题,只是每个点可以走多次,求回到起点的最短距离(起点为点0). 分析:状态压缩,先预处理各点之间的最短路,然后sum[i][buff]表示在i点,状态为buff时所耗时...... ...
- Linux下并发网络设计之I/O复用
I/O 流: 首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象. 不管是文件,还是套接字,还是管道,我们都可以把他们看作流. 之后我们来讨论I/O的操作 ...
- js字面量
以前一直对js字面量模棱两可. '字面量是一种表示值的记法.' js字面量(literal) 分为以下几个 number literal 8 就是数字字面量 string liter ...