HDU 5642 King's Order 动态规划
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 动态规划的更多相关文章
- HDU 5642 King's Order dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 King's Order Accepts: 381 Submissions: 1361 ...
- hdu 5642 King's Order(数位dp)
Problem Description After the king's speech , everyone is encouraged. But the war is not over. The k ...
- HDU 5642 King's Order【数位dp】
题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=677&pid=1003 题意: 求长度为n的序列 ...
- HDU 1074 Doing Homework (动态规划,位运算)
HDU 1074 Doing Homework (动态规划,位运算) Description Ignatius has just come back school from the 30th ACM/ ...
- HDU 1176 免费馅饼 (动态规划)
HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...
- hdu-5642 King's Order(数位dp)
题目链接: King's Order Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- King's Order(hdu5642)
King's Order Accepts: 381 Submissions: 1361 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 5433 Xiao Ming climbing 动态规划
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5433 Xiao Ming climbing Time Limit: 2000/1000 MS (Ja ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
随机推荐
- 安装完ODTwithODAC112012,出现ORA-12560:TNS:协议适配器错误
参考:http://blog.csdn.net/tan_yixiu/article/details/6762357 操作系统:windows2008 Enterprise 64位 开发工具:VS201 ...
- 【51nod1006】simple KMP
原题意看的挺迷糊的,后来看了http://blog.csdn.net/YxuanwKeith/article/details/52351335大爷的题意感觉清楚的多…… 做法也非常显然了,用树剖维护后 ...
- nginx配置--event模块
在nginx的配置中,event模块可以进行以下配置: 设置网络连接的序列化. 在Nginx服务器的多进程下,有可能出现惊群(Thundering herd problem)问题,指的是当某一个时刻只 ...
- .htaccess技巧: URL重写(Rewrite)与重定向(Redirect)
URL重定向是.htaccess的重头戏,它可以将长地址转为短地址.将动态地址转为静态地址.重定向丢失的页面.防止盗链.实现自动语言转换等.笔者觉得难点是在正则表达式的运用和理解上. 实现所有这些神奇 ...
- UFT12.续期的操作方法
安装完毕UFT后,页面中报install错误,此时报此错误的原因是因为UFT的许可证过期了,解决方法如下: 方法是找到C:\ProgramData目录下的SafeNet Sentinel文件夹将其删除 ...
- ASP.NET Core 2.0 MVC 发布部署--------- CentOS7 X64 具体操作
.Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...
- mysql 数据库备份及恢复
1.备份 # 导出数据库:mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -–add-drop-table -uusername -ppassword da ...
- PHP下利用PHPMailer
PHPMailer有什么优点? 可运行在任何平台之上 支持SMTP验证 发送邮时指定多个收件人,抄送地址,暗送地址和回复地址:注:添加抄送.暗送仅win平台下smtp方式支持 支持多种邮件编码包括:8 ...
- MySQL-事务特性
1. 事务概念引入: 现实生活中,我们往往经常会进行转账操作,转账操作可以分为两部分来完成,转入和转出.只有这两部分都完成了才可以认为是转账成功.在数据库中,这个过程是使用两条语句来完成的,如果其中任 ...
- Windows内核读书笔记——Windows异常分发处理机制
本篇读书笔记主要参考自<深入解析Windows操作系统>和<软件调试>这两本书. IDT是处理异常,实现操作系统与CPU的交互的关口. 系统在初始化阶段会去填写这个结构. ID ...