Codeforces Gym100735 G.LCS Revised (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

G.LCS Revised

 

The longest common subsequence is a well known DP problem: given two strings A and B, one has to compute the maximum length of a subsequence that's common to both A and B.

In this particular problem we work with strings A and B formed only by 0 and 1, having the same length. You're given a string A of length n. Iterate all strings B possible. There are 2n of them. Calculate, for each string B, the longest common subsequence of A and B. Then, output the minimum length obtained.

Input

The first and the only line of the input contains string A, formed only by 0 and 1. It's guaranteed that the length is between 1 and 105.

Output

Output a single number - the requested length.

Example
Input
101010
Output
3

超级无敌大水题,直接找0和1哪个少就可以。。。

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 const int N=1e6+10;
 6 char a[N];
 7 int main(){
 8     while(~scanf("%s",a)){
 9         int len=strlen(a);
10         int ans,num1=0,num2=0;
11         for(int i=0;i<len;i++){
12             if(a[i]=='1')num1++;
13             else num2++;
14         }
15         ans=min(num1,num2);
16         printf("%d
",ans);
17     }
18     return 0;
19 }
原文地址:https://www.cnblogs.com/ZERO-/p/9703208.html