How to Type

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6787    Accepted Submission(s):
3057

Problem Description
Pirates have finished developing the typing software.
He called Cathy to test his typing software. She is good at thinking. After
testing for several days, she finds that if she types a string by some ways, she
will type the key at least. But she has a bad habit that if the caps lock is on,
she must turn off it, after she finishes typing. Now she wants to know the
smallest times of typing the key to finish typing a string.
 
Input
The first line is an integer t (t<=100), which is
the number of test case in the input file. For each test case, there is only one
string which consists of lowercase letter and upper case letter. The length of
the string is at most 100.
 
Output
For each test case, you must output the smallest times
of typing the key to finish typing this string.
 
Sample Input
3
Pirates
HDUacm
HDUACM
 
Sample Output
8
8
8

Hint

The string “Pirates”, can type this way, Shift, p, i, r, a, t, e, s, the answer is 8.
The string “HDUacm”, can type this way, Caps lock, h, d, u, Caps lock, a, c, m, the answer is 8
The string "HDUACM", can type this way Caps lock h, d, u, a, c, m, Caps lock, the answer is 8

 
Author
Dellenge
 
Source
类似于上次写的那道可以上下右走方格的题目,也是常见的一类DP,有一种分层的思想!
对于此题就在于Caps键在DP的过程中可能处于开/关两种,我们不妨多开一维0表示Caps键处于关闭1表示处于开启状态.
直接地推1Ahhh,还是在喝了酒之后好开森>_<

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int dp[105][2];
char s[105];
int solve()
{
int i,j,k,sz=strlen(s);
memset(dp,inf,sizeof(dp));
if(islower(s[0])){
dp[0][0]=1;
dp[0][1]=2;
}
else{
dp[0][0]=2;
dp[0][1]=2;
}
for(i=1;i<sz;++i){
if(islower(s[i])){
dp[i][0]=min(dp[i-1][1]+2,dp[i-1][0]+1);
dp[i][1]=min(dp[i-1][1]+2,dp[i-1][0]+2);
}
else{ //da xie
dp[i][0]=min(dp[i-1][1]+2,dp[i-1][0]+2);
dp[i][1]=min(dp[i-1][1]+1,dp[i-1][0]+2);
}
}
return min(dp[sz-1][0],dp[sz-1][1]+1);
}
int main()
{
int t,n,m,i,j;
cin>>t;
while(t--){cin>>s;
cout<<solve()<<endl;
}
return 0;
}

HDU 2577 分情况多维DP的更多相关文章

  1. HDU - 2159 FATE(二维dp之01背包问题)

    题目: ​ 思路: 二维dp,完全背包,状态转移方程dp[i][z] = max(dp[i][z], dp[i-1][z-a[j]]+b[j]),dp[i][z]表示在杀i个怪,消耗z个容忍度的情况下 ...

  2. HDU 2577 How to Type(dp题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...

  3. HDU 2577 How to Type (线性dp)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. hdu 1437 天气情况【概率DP】

    天气情况 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu 2577 How to Type(DP)

    How to Type Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. HDU 2577 How to Type【DP】

    题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...

  7. DP问题(1) : hdu 2577

    题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...

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

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

  9. 关于二维DP————站上巨人的肩膀

    意匠惨淡经营中ing, 语不惊人死不休........ 前几天学了DP,做了个简单的整理,记录了关于DP的一些概念之类的,今天记录一下刚学的一个类型 ----关于二维DP 那建立二维数组主要是干嘛用的 ...

随机推荐

  1. RAC 性能分析 - 'log file sync' 等待事件

    简介 本文主要讨论 RAC 数据库中的'log file sync' 等待事件.RAC 数据库中的'log file sync' 等待事件要比单机数据库中的'log file sync' 等待事件复杂 ...

  2. Redis主从切换

    案例 易车网:http://www.greatops.net/?id=232 redis主从切换:http://www.cnblogs.com/itdragon/p/7932178.htmlhttps ...

  3. Mysql中datetime和timestamp区别

    DATETIME日期和时间的组合.支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'.MySQL以'YYYY-MM-DD HH:MM:SS'格式显示DA ...

  4. 在线学习--online learning

    在线学习 online learning Online learning并不是一种模型,而是模型的训练方法.能够根据线上反馈数据,实时快速的进行模型调优,使得模型能够及时反映线上的变化,提高线上预测的 ...

  5. 常微分方程初值问题:多步预测-修正方法 [MATLAB]

    #先上代码后补笔记# #可以直接复制粘贴调用的MATLAB函数代码!# 1. 亚当斯(Adams)预测-修正算法 由亚当斯-巴什福特(Adams-Bashforth)显式预测公式和亚当斯-莫顿(Ada ...

  6. Linux系统——公网定制化yum仓库部署

    1)搭建公网源yum仓库 安装wget aliyun源 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel ...

  7. iview使用vue-i18n实现国际化

    iview官网中和网上的例子中使用的都是webpack方式,需要import js文件,但是由于项目架构比较简单,没有使用webpack,纯html和js进行交互.所以这里就直接使用js文件引用方式. ...

  8. bzoj1604 / P2906 [USACO08OPEN]牛的街区Cow Neighborhoods

    P2906 [USACO08OPEN]牛的街区Cow Neighborhoods 考虑维护曼哈顿距离:$\left | x_{1}-x_{2} \right |+\left | y_{1}-y_{2} ...

  9. Solr DIH query 工作流

    本文地址 http://www.cnblogs.com/jasonxuli/p/6491270.html DataImportHandler (DIH) 支持全量数据导入和增量数据导入,主要有四个qu ...

  10. 20145221 《Java程序设计》课程总结

    20145221 <Java程序设计>课程总结 每周读书笔记链接汇总 Atom使用心得 - 21世纪的编辑器 网络安全攻防学习平台 - 基础关 Java实现:数据结构之排序 2014522 ...