http://codeforces.com/problemset/problem/150/B

题意:

给出n,m,k,n表示字符串的长度为n,m表示字符种类个数,k表示每k个数都必须是回文串,求满足要求的不同字符串有多少种。

思路:
分奇偶推一下,当k为偶数时,容易发现如果n=k,那么有最多有k/2种不同的字符可填,如果n>k,你会发现此时所有位置都必须一样。

奇数的话会稍微麻烦一点,如果n=k,那么最多有k/2+1种不同的字符可填,如果n>k,你会发现此时最后只有2中不同的字符可填。

 #include<iostream>
#include<cstdio>
using namespace std;
const int maxn = +;
const int mod = 1e9+;
int n,m,k; int main()
{
scanf("%d%d%d",&n,&m,&k);
if(k==)
{
long long ans = ;
for(int i=; i<=n; i++)
{
ans*=m;
ans%=mod;
}
printf("%lld\n",ans);
return ;
}
if(n<k)
{
long long ans = ;
for(int i=; i<=n; i++)
{
ans*=m;
ans%=mod;
}
printf("%lld\n",ans);
return ;
}
if(k%==)
{
if(n==k)
{
long long ans = ;
for(int i=; i<=k/; i++)
{
ans*=m;
ans%=mod;
}
printf("%lld\n",ans);
}
else printf("%d\n",m);
}
if(k&)
{
long long ans = ;
if(n==k)
{
for(int i=; i<=k/+; i++)
{
ans*=m;
ans%=mod;
}
}
else ans = m*m;
printf("%lld\n",ans);
}
return ;
}

Codeforces Round #107 (Div. 1) B. Quantity of Strings(推算)的更多相关文章

  1. 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

    题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...

  2. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  3. Codeforces Round #107 (Div. 2)

    D题 并查集+组合 #include <iostream> #include <cstdio> #include <cstring> using namespace ...

  4. Codeforces Round #107 (Div. 2)---A. Soft Drinking

    Soft Drinking time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...

  6. Codeforces Round #254 (Div. 1) D - DZY Loves Strings

    D - DZY Loves Strings 思路:感觉这种把询问按大小分成两类解决的问题都很不好想.. https://codeforces.com/blog/entry/12959 题解说得很清楚啦 ...

  7. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  8. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)

    题目链接:http://www.codeforces.com/problemset/problem/281/A题意:将一个英文字母的首字母变成大写,然后输出.C++代码: #include <c ...

  9. Codeforces Round #358 (Div. 2) D. Alyona and Strings dp

    D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...

随机推荐

  1. Shell变量相关

    li@ubuntu:~/test$ vi test.sh li@ubuntu:~/test$ cat test.sh #!/bin/bash #shell变量不加引号;加单引号;加双引号都行 url= ...

  2. POJ 3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Bessie has gone to the mall's jewelry store and spies a charm br ...

  3. java -cp & java jar的区别

    java -cp java -cp 和 -classpath 一样,是指定类运行所依赖其他类的路径,通常是类库和jar包,需要全路径到jar包,多个jar包之间连接符:window上分号“;”.Lin ...

  4. maven 项目 查询部分关心的字段

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...

  5. MyEclipse10.7安装Aptana后重启:An internal error has occurred. No more handles [Could not detect registered XULRunner to use]

    问题描述: 当安装Aptana插件后重启MyEclipse10.7,发生错误: An internal error has occurred. No more handles [Could not d ...

  6. SRTP参数及数据包处理过程(转)

    源: SRTP参数及数据包处理过程

  7. intelliJ IDEA之使用svn或git管理代码

    intelliJ IDEA之使用svn管理代码 1.VCS—>import into Version Control—>Share Project(Subversion) 2.点击+    ...

  8. java中的基本数据类型和引用数据类型

    java中基本数据类型有8种:byte,short,int,long,char,float,double,boolean 整型有四种:byte short,int,long byte:   1字节   ...

  9. nginx的gzip压缩功能

    我们在开发网站的时候,应该要考虑到pv,因为pv比较大可能会造成服务器带宽不够用,进而导致用户体验变差. 这个时候我们就可以考虑用nginx的gzip功能. 在nginx中开启gzip压缩功能很简单, ...

  10. ORA-38301: 无法对回收站中的对象执行 DDL/DML

    我们是在生产系统中遇到,清空回收站,然后禁用回收站即可,这样后面就不会发生,单纯禁用可能仍会报错,因为不会自动清空回收站. purge recyclebin; alter system set rec ...