HDU-2577 how to type DP

Source: Internet
Author: User

Character Input is incorrect. At first, the SHIFT + character input is not considered as the character in the opposite state of the current case lock status. Only two steps are required.

State transition equation: dp1 [I] indicates the number of steps required for the capitalized State after the I character is entered. dp2 [I] indicates the number of steps required for the lowercase state after the I character is entered.

If the I character is lower case:

Dp1 [I] = min (dp1 [I-1] + 2, dp2 [I-1] + 2 );
Dp2 [I] = min (dp1 [I-1] + 2, dp2 [I-1] + 1 );

If the I-th character is uppercase:

Dp1 [I] = min (dp1 [I-1] + 1, dp2 [I-1] + 2 );

Dp2 [I] = min (dp1 [I-1] + 2, dp2 [I-1] + 2 );

#include <iostream>#include <cstdio>#include <cmath>#include <queue>#include <vector>#include <cstring>#include <algorithm>using namespace std;char s[111];int dp1[111];int dp2[111];int main(){int t;scanf("%d",&t);while(t--){scanf("%s",s);int len=strlen(s);if(s[0]>='A'&&s[0]<='Z'){dp1[0]=2;dp2[0]=2;}else{dp1[0]=2;dp2[0]=1;}for(int i=1;i<len;i++){if(s[i]>='A'&&s[i]<='Z'){dp1[i]=min(dp1[i-1]+1,dp2[i-1]+2);dp2[i]=min(dp1[i-1]+2,dp2[i-1]+2);}else{dp1[i]=min(dp1[i-1]+2,dp2[i-1]+2);dp2[i]=min(dp1[i-1]+2,dp2[i-1]+1);}}cout<<dp2[len-1]<<endl;}return 0;}


HDU-2577 how to type DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.