hdu 2577 How to Type(很爽良好玩的DP)
hdu 2577 How to Type(很爽很好玩的DP)How to TypeTime Limit: 2000/1000 MS (Java/Others)????Memory Lim
hdu 2577 How to Type(很爽很好玩的DP)
How to Type
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 842????Accepted Submission(s): 364
#include <iostream>#include <stdio.h>#include <memory.h>using namespace std;char ch[105];int on[105]; //打开大写int off[105]; //关闭大写int main(){ int i, t, len; scanf("%d", &t); while(t--) { scanf("%s", ch); len = strlen(ch); off[0] = 0; //刚开始的没开灯 on[0] = 1; //开灯的要+1 for(i = 0; i < len; i++) { if(ch[i] >= 'a' && ch[i] <= 'z') //小写字母 { //开:(开~~shift+type, 关~~type+开灯) on[i+1] = min(on[i] + 2, off[i] + 2); //关:(开~~lock+type, 关~~type) off[i+1] = min(on[i] + 2, off[i] + 1); } else //大写字母 { //开:(开~~type, 关~~开灯+type) on[i+1] = min(on[i] + 1, off[i] + 2); //关:(开~~lock+type, 关~~shift+type) off[i+1] = min(on[i] + 2, off[i] + 2); } } on[len]++; printf("%d\n", min(on[len], off[len])); } return 0;}?