【HDOJ】2577 How to Type

DP。

 /* 2577 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 125
#define isUpper(ch) (ch>='A' && ch<='Z') char s[MAXN];
int dp[MAXN][]; int min(int a, int b) {
return a<b? a:b;
} int main() {
int t, l;
int i, j, k;
int ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
#endif scanf("%d", &t);
while (t--) {
scanf("%s", s+);
memset(dp, , sizeof(dp));
dp[][] = ;
dp[][] = ;
for (i=; s[i]; ++i) {
if ( isUpper(s[i]) ) {
dp[i][] = + min(dp[i-][]+, dp[i-][]+);
dp[i][] = + min(dp[i-][], dp[i-][]+);
} else {
dp[i][] = + min(dp[i-][], dp[i-][]+);
dp[i][] = + min(dp[i-][]+, dp[i-][]+);
}
}
ans = min(dp[i-][], dp[i-][]+);
printf("%d\n", ans);
} return ;
}
上一篇:Duilib第一步(III)-知识进阶


下一篇:大数据入门第五天——离线计算之hadoop(上)概述与集群安装