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. Oracle数据类型char与varchar的对比

    使用scott用户连接数据库 新建一个表 create table stu01(name char(32)); 插入一条数据 insert into stu01 values('liuyueming' ...

  2. AutoLayout性能不如frame

    http://draveness.me/layout-performance.html 复杂视图, 数量超过30个,用autoLayout就比较卡顿了 发现首页类似朋友圈,卡顿的原因应该就是使用了au ...

  3. (2.10)Mysql之SQL基础——约束及主键重复处理

    (2.10)Mysql之SQL基础——约束及主键重复处理 关键词:mysql约束,批量插入数据主键冲突 [1]查看索引: show index from table_name; [2]查看有约束的列: ...

  4. mysql 数据操作 单表查询

    单表查询的语法 distinct 去重 SELECT 字段1,字段2... FROM 表名 库.表名 WHERE 条件 过滤 符合条件的 GROUP BY field 分组条件 HAVING 筛选 过 ...

  5. jquery序列化表单以及回调函数的使用

    在开发项目中.将前台的值传给后台,有时的JSP表单中的值有一两个,也有所有的值,假设这时一个个传,必然不是非常好的办法,所以使用jQuery提供的表单序列化方法,能够非常好的解决问题.同一时候能够封装 ...

  6. centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课

    centos shell编程4[分发系统] 服务器标准化  mkpasswd 生成密码的工具  expect讲解   expect传递参数   expect自动同步文件  expect指定host和要 ...

  7. Linux中的Buffer Cache和Page Cache echo 3 > /proc/sys/vm/drop_caches Slab内存管理机制 SLUB内存管理机制

    Linux中的Buffer Cache和Page Cache echo 3 > /proc/sys/vm/drop_caches   Slab内存管理机制 SLUB内存管理机制 http://w ...

  8. 【转】Deep Learning(深度学习)学习笔记整理系列之(六)

    9.3.Restricted Boltzmann Machine (RBM)限制波尔兹曼机 假设有一个二部图,每一层的节点之间没有链接,一层是可视层,即输入数据层(v),一层是隐藏层(h),如果假设所 ...

  9. mysql索引之主键索引

    MySQL目前主要有以下几种索引类型:1.普通索引2.唯一索引3.主键索引4.组合索引5.全文索引 二.语句 CREATE TABLE table_name[col_name data type] [ ...

  10. centos设置代理上网

    centos设置代理上网   假设我们要设置代理为 IP:PORT 1.网页上网 网页上网设置代理很简单,在firefox浏览器下 Edit-->>Preferences-->> ...