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. SQL---->mySQl数据库1------数据库的增删改查备份恢复

    1.在终端输入:mysql -uroot -p      然后输入密码,进入客户端 2.输入:\s 3.创建数据库 3.1创建字符集是utf-8的数据库 3.2创建带校验规则的数据库,校验规则可以在a ...

  2. 无题II---hdu2236(二分,匈牙利)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2236 要求最大值与最小值的差值最小,是通过枚举边的下限和上限来完成 只需要用二分找一个区间,然后不断枚 ...

  3. paramiko与ssh

    一.paramiko模块的安装 paramiko模块依赖PyCrypto模块,而PyCrypto需要GCC库编译,不过一般发行版的源里带有该模块.这里以centos6为例,直接借助以下命令可以直接完成 ...

  4. Mirror--生成用于镜像用户同步的脚本

    USE master GO IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL DROP PROCEDURE sp_hexadecimal GO CREATE PR ...

  5. [World Wind学习]21.影像切割

    本来希望从GlobeMapper中生成切片直接加载到WorldWind中,但是没有成功!所以想比较一下和dstile生成的瓦片到底有什么区别? 所以这才第一次生成并加载了影像瓦片.貌似和GlobeMa ...

  6. Django REST Framework简单入门(一)

    Django REST Framework(简称DRF),是一个用于构建Web API的强大且灵活的工具包. REST这个词,是Roy Thomas Fielding在他2000年的博士论文中提出的. ...

  7. PAT 1139 First Contact[难][模拟]

    1139 First Contact(30 分) Unlike in nowadays, the way that boys and girls expressing their feelings o ...

  8. 2017中国大学生程序设计竞赛-哈尔滨站 Solution

    A - Palindrome 题意:给出一个字符串,找出其中有多少个子串满足one-half-palindromic 的定义 思路:其实就是找一个i, j  使得 以i为中轴的回文串长度和以j为中轴的 ...

  9. 对Man-In-The-Middle攻击的一点理解

    1)    中间人攻击最容易理解的可能就是fiddler吧,他可以截获request重新组织request的数据,有个专业的攻击工具叫burp. 2)    数据存在immutable,mutable ...

  10. Linux /python --- zipinfo命令

    Linux zipinfo命令用于列出压缩文件信息. 执行zipinfo指令可得知zip压缩文件的详细信息. zipinfo [-12hlmMstTvz][压缩文件][文件...][-x <范本 ...