King's Order

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5642

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

hint:

All the order that has length 2 are legal. So the answer is 26*26.

For the order that has length 4. The illegal order are : "aaaa" , "bbbb"…….."zzzz" 26 orders in total. So the answer for n == 4 is 26^4-26 = 456950

hint:

For the first testcase you can divide the into one cake of \(2\times2\) , 2 cakes of \(1\times 1\)

Hint

题意

问你长度为n的字符串,只含有小写字母。

没有超过3个连续相同。

问你这个字符串一共有多少种。

题解:

dp[i][j]表示第i个位置,当前连续长度为j的方案数。

然后转移就好了。

可以直接预处理出来。

代码

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<cstring>
using namespace std; const int mod = 1e9+7;
const int maxn = 2000+7; long long dp[maxn][4];
void pre()
{
dp[1][1]=26;
for(int i=1;i<=2000;i++)
{
for(int j=1;j<=3;j++)
{
if(dp[i][j])
{
if(j!=3)dp[i+1][j+1]=(dp[i][j]+dp[i+1][j+1])%mod;
dp[i+1][1]=(dp[i+1][1]+dp[i][j]*25)%mod;
}
}
}
}
void solve()
{
int n;scanf("%d",&n);
long long ans = 0;
for(int i=1;i<=3;i++)
ans=(ans+dp[n][i])%mod;
cout<<ans<<endl;
}
int main()
{
int t;scanf("%d",&t);
pre();
while(t--)solve();
return 0;
}

HDU 5642 King's Order 动态规划的更多相关文章

  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 1074 Doing Homework (动态规划,位运算)

    HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...

  5. HDU 1176 免费馅饼 (动态规划)

    HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...

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

    题目链接: King's Order Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  7. King's Order(hdu5642)

    King's Order  Accepts: 381  Submissions: 1361  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  8. HDU 5433 Xiao Ming climbing 动态规划

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...

  9. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

随机推荐

  1. Java容器---基本概念

    1.持有对象 Java容器类类库的用途是“保存对象”,并将其划分为两个不同的概念: (1) Collection: 一个独立元素的序列,这些元素都服从一条或多条规则.List必须按照插入的顺序保存元素 ...

  2. windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include       vhost.conf; (或者新建vhost ...

  3. CSU 1416 Practical Number

    原题链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1416 结论题,具体判断方法请点击这个网址. 筛素数是肯定的,但一开始定的范围太大了,想当 ...

  4. 洛谷P1554 梦中的统计 题解

    题目传送门 这道题暴力又让我过了...数据真的很水(luogu) 暴力枚举n~m的每个数,再统计一次,交付评测...AC #include<bits/stdc++.h> using nam ...

  5. Hadoop(四)HDFS的高级API操作

    一 HDFS客户端环境准备 1.1 jar包准备 1)解压hadoop-2.7.6.tar.gz到非中文目录 2)进入share文件夹,查找所有jar包,并把jar包拷贝到_lib文件夹下 3)在全部 ...

  6. AC日记——#2057. 「TJOI / HEOI2016」游戏 LOJ

    #2057. 「TJOI / HEOI2016」游戏 思路: 最大流: 代码: #include <cstdio> #include <cstring> #include &l ...

  7. 保存最后N个元素

    cookbook系列 问题:对要搜索的值的最后几项做个有限的历史记录. 方案: #coding=utf- from collections import deque def search(lines, ...

  8. 关闭webstorm自动保存,并显示文件未保存标识

    1.取消自动保存 2.显示编辑状态设置:

  9. 【LOJ】#2010. 「SCOI2015」小凸解密码

    题解 断环为链,把链复制两份 用set维护一下全是0的区间,然后查找x + n / 2附近的区间,附近各一个过不去,最后弃疗了改为查附近的两个,然后过掉了= = 熟练掌握stl的应用,你值得拥有(雾 ...

  10. checkbox 更改样式

    html: <div class="wrap"> <p>1. 勾选</p> <input type="checkbox" ...