CodeForcesGym 100735G LCS Revised

LCS Revised

Time Limit: 2000ms
Memory Limit: 65536KB
This problem will be judged on  CodeForcesGym. Original ID: 100735G
64-bit integer IO format: %I64d      Java class name: (Any)
 

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.

 

Sample Input

Input
101010
Output
3

Source

 
解题:坑爹题
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 100010;
 4 char str[maxn];
 5 int main() {
 6     while(~scanf("%s",str)) {
 7         int one = 0,zero = 0;
 8         for(int i = 0; str[i]; ++i)
 9             if(str[i] == '0') zero++;
10             else one++;
11         printf("%d\n",min(zero,one));
12     }
13     return 0;
14 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4812497.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值