HDU 2577 分情况多维DP
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
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.
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.
of typing the key to finish typing this string.
Pirates
HDUacm
HDUACM
8
8
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
#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的更多相关文章
- 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个容忍度的情况下 ...
- HDU 2577 How to Type(dp题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2577 解题报告:有一个长度在100以内的字符串,并且这个字符串只有大写和小写字母组成,现在要把这些字符 ...
- HDU 2577 How to Type (线性dp)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 1437 天气情况【概率DP】
天气情况 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu 2577 How to Type(DP)
How to Type Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 2577 How to Type【DP】
题意:给出一个字符串,有大写有小写,问最少的按键次数.然后打字的这个人有一个习惯,打完所有的字之后,指示灯要关闭. dp[i][j]表示打到第i个字母,j有0,1两个值表示指示灯开或者关的状态 然后就 ...
- DP问题(1) : hdu 2577
题目转自hdu 2577,题目传送门 题目大意: 现给你n个区分大小写的字符串,大小写可用Caps Lock和shift切换(学过计算机的都知道) 但是有一点需要注意(shift是切换,若现在是大写锁 ...
- HDU 5787 K-wolf Number (数位DP)
K-wolf Number 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5787 Description Alice thinks an integ ...
- 关于二维DP————站上巨人的肩膀
意匠惨淡经营中ing, 语不惊人死不休........ 前几天学了DP,做了个简单的整理,记录了关于DP的一些概念之类的,今天记录一下刚学的一个类型 ----关于二维DP 那建立二维数组主要是干嘛用的 ...
随机推荐
- Oracle安装部署之 6节点11g cluster环境搭建
**********************集群规划*************************************** --配置主机,共需要8台主机,其中6台做grid集群,1台作为存储服 ...
- python基础之练习题(二)
九九乘法表 i = 0 #while 九九乘法表 j = 0 while i < 9: i += 1 while j<9: j += 1 sum = i + j total="% ...
- 代码处理 iOS 的横竖屏旋转
一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...
- go-004-数据结构
在 Go 编程语言中,数据类型用于声明函数和变量. 数据类型的出现是为了把数据分成所需内存大小不同的数据,编程的时候需要用大数据的时候才需要申请大内存,就可以充分利用内存. Go 语言按类别有以下几种 ...
- [py][lc]python高阶函数(匿名/map/reduce/sorted)
匿名函数 - 传入列表 f = lambda x: x[2] print(f([1, 2, 3])) # x = [1,2,3] map使用 传入函数体 def f(x): return x*x r ...
- WebDriver API 实例详解(二)
十一.双击某个元素 被测试网页的html源码: <html> <head> <meta charset="UTF-8"> </head&g ...
- 在jQuery中解决事件冒泡问题
<pre name="code" class="html">事件会按照DOM层次结构像水泡一样不断向上直至顶端 解决方法:在事件处理函数中返回fal ...
- 使用scikit-learn 估计器分类
本章的几个概念: 估计器(estimator) 用于分类.聚类和回归分析 转换器(transformer):用于数据预处理回来数据转换 流水线(pipeline): ...
- redis error MISCONF Redis is configured to save RDB snapshots
在操作命令incr时发生错误: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able ...
- java基础知识 构造方法
在java里面,构造方法也就是构造函数 构造函数=构造方法;构造方法是一种特殊的方法,具有以下特点.(1)构造方法的方法名必须与类名相同.(2)构造方法没有返回类型,也不能定义为void,在方法名前面 ...