题目链接:

King's Order

Time Limit: 2000/1000 MS (Java/Others)  

  Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 101    Accepted Submission(s): 59

Problem Description
After the king's speech , everyone is encouraged. But the war is not over. The king needs to give orders from time to time. But sometimes he can not speak things well. So in his order there are some ones like this: "Let the group-p-p three come to me". As you can see letter 'p' repeats for 3 times. Poor king!

Now , it is war time , because of the spies from enemies , sometimes it is pretty hard for the general to tell which orders come from the king. But fortunately the general know how the king speaks: the king never repeats a letter for more than 3 times continually .And only this kind of order is legal. For example , the order: "Let the group-p-p-p three come to me" can never come from the king. While the order:" Let the group-p three come to me" is a legal statement.

The general wants to know how many legal orders that has the length of n

To make it simple , only lower case English Letters can appear in king's order , and please output the answer modulo 1000000007

We regard two strings are the same if and only if each charactor is the same place of these two strings are the same.

 
Input
The first line contains a number T(T≤10)——The number of the testcases.

For each testcase, the first line and the only line contains a positive number n(n≤2000).

 
Output
For each testcase, print a single number as the answer.
 
Sample Input
2
2
4
 
Sample Output
676
456950
题意:
国王演讲后士气大增,但此时战争还没有结束,国王时不时要下发命令。

由于国王的口吃并没有治愈,所以传令中可能出现:“让第三军-军-军,到前线去” 这样的命令。由于大洋国在军队中安插了间谍 , 战事紧急,很多时候前线的指挥官不能分清哪些命令真正来自国王。但国王的命令有一个特点,他每次连续重复的字符最多 33 次. 所以说他的命令中没有:“让第三军-军-军-军 , 到前线去”,但是可以有 :“让第三军-军 , 到前线去” 。

此时将军找到了你,你需要告诉他,给定命令的长度长度为 nn,有多少种不同的命令可以是国王发出的 。(也就是求长度为 nn 的合格字符串的个数)当然,国王可能说出一句话没有犯任何口吃,就像他那次演讲一样。

为了简化答案,国王的命令中只含有小写英文字母,且对答案输出模 1000000007。

我们认为两个命令如果完全相同那么这两个字符串逐个比较就完全相同。

思路:dp[i][j][k]  i为字符串的第i个字符,'a'+j为结尾的字符,k为结尾的字符出现了几次,具体的转移方程看代码;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const long long mod=1e9+;
long long dp[][][];
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(dp,,sizeof(dp));
for(int i=;i<;i++)
{
dp[][i][]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=;j++)//枚举结尾的字符
{
for(int k=;k<;k++)//枚举新加的字符
{
if(k==j)
{
for(int x=;x<=;x++)
dp[i][j][x]+=dp[i-][j][x-],dp[i][j][x]%=mod;//相等的话加一块
}
else
{
for(int x=;x<=;x++)
dp[i][j][]+=dp[i-][j][x],dp[i][j][]%=mod;//不等的话x不加
} }
}
}
long long ans=;
for(int i=;i<;i++)
{
for(int j=;j<=;j++)
ans+=dp[n][i][j],ans%=mod;
}
cout<<ans<<"\n";
}
return ;
}

hdu-5642 King's Order(数位dp)的更多相关文章

  1. HDU 5642 King's Order dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 King's Order  Accepts: 381  Submissions: 1361   ...

  2. hdu 5642 King's Order(数位dp)

    Problem Description After the king's speech , everyone is encouraged. But the war is not over. The k ...

  3. HDU 5642 King's Order【数位dp】

    题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...

  4. HDU 5642 King's Order 动态规划

    King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...

  5. HDU 4507 (鬼畜级别的数位DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4507 题目大意:求指定范围内与7不沾边的所有数的平方和.结果要mod 10^9+7(鬼畜の元凶) 解题 ...

  6. HDU 5787 K-wolf Number (数位DP)

    K-wolf Number 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5787 Description Alice thinks an integ ...

  7. 【HDU 3652】 B-number (数位DP)

    B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...

  8. HDU 5787 K-wolf Number(数位DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5787 [题目大意] 求区间[L,R]内十进制数相邻k位之间不相同的数字的个数. [题解] 很显然的 ...

  9. 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】

    Valley Numer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. 走进EC6的let和const命令

    详细学习链接: http://es6.ruanyifeng.com/#docs/let let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命 ...

  2. 驱动程序分层分离概念_总线驱动设备模型_P

    分层概念: 驱动程序向上注册的原理: 比如:输入子程序一个input.c作为一层,下层为Dev.c和Dir.c,分别编写Dev.c和Dir.c向上Input.c注册:如图所示 分离概念: 分离概念主要 ...

  3. lua(注册c库)

    #include <iostream> #include <string.h> extern "C" { #include "lua-5.2.2/ ...

  4. fzu2020( c(n,m)%p,其中n, m, p (1 <= m <= n <= 10^9, m <= 10^4, m < p < 10^9, p是素数) )

    基本的模板题,统计分子分母中p出现的次数,然后求逆元取模. // // main.cpp // fzu2020 // // Created by 陈加寿 on 15/12/27. // Copyrig ...

  5. lucas定理证明

    Lucas 定理(证明) A.B是非负整数,p是质数.AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0]. 则组合数C(A,B)与C(a[n],b[n])* ...

  6. (转)Java并发编程:阻塞队列

    原文地址: http://www.cnblogs.com/dolphin0520/p/3932906.html 一.几种主要的阻塞队列 自从Java 1.5之后,在java.util.concurre ...

  7. 如何使用EasyNVR+CDN突破萤石云在直播客户端数量上的限制,做到低成本高性价比的直播

    恰逢五一假期,有以为来自内蒙的用户向我电话咨询,大概的场景是这样的: 目前用户使用的是全套的海康IPC和NVR设备: 海康NVR设备通过设置萤石云平台,由萤石云对外提供直播服务: 萤石云对单个摄像机同 ...

  8. python login form

    import time from selenium import webdriver browser = webdriver.Chrome() wait_time = 1 USER = 'xl.fen ...

  9. JavaScript-Confirm用法

    function checkMobileBind() {    if(confirm('您尚未绑定手机,是否前往绑定?'))    {        window.location='http://m ...

  10. Delphi 64与32位的差异

    Delphi 64与32位的差异   最近,Delphi推出了64位预览版本, 我做为一个忠实的Delphier, 看到这消息后,第一时间学习,并写下这个做为以后的参考资料. 相同点: 在Delphi ...