题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2577
一道挺有意思的dp题
主要就是有两个二维数组存放两个状态吧
大写和小写
dp[i][j] j就代表打完这个字之后的状态
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
int dp[105][2];
char str[105];
int main()
{
// std::ios::sync_with_stdio(false);
int t,i;
scanf("%d",&t);
getchar();
while(t--)
{
memset(dp,0,sizeof(dp));
memset(str,'\0',sizeof(str));
scanf("%s",str+1);
dp[0][1]=1;
for(i=1;i<=strlen(str+1);i++)
{
if(str[i]<='z'&&str[i]>='a')
{//cout<<"qqqq"<<endl;
dp[i][0]=min(dp[i-1][0]+1,dp[i-1][1]+2);
dp[i][1]=min(dp[i-1][0]+2,dp[i-1][1]+2);
}
else
{
// cout<<"www"<<endl;
dp[i][0]=min(dp[i-1][0]+2,dp[i-1][1]+2);
dp[i][1]=min(dp[i-1][0]+2,dp[i-1][1]+1);
// cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
}
}
dp[strlen(str+1)][1]++;
cout<<min(dp[strlen(str+1)][0],dp[strlen(str+1)][1])<<endl;
}
return 0;
}