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\n",ans);
17 }
18 return 0;
19 }

Codeforces Gym100735 G.LCS Revised (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)的更多相关文章

  1. Codeforces Gym100735 D.Triangle Formation (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    日常训练题解 D.Triangle Formation You are given N wooden sticks. Your task is to determine how many triang ...

  2. Codeforces Gym100735 I.Yet another A + B-Java大数 (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    I.Yet another A + B You are given three numbers. Is there a way to replace variables A, B and C with ...

  3. Codeforces Gym100735 E.Restore (KTU Programming Camp (Day 1) Lithuania, Birˇstonas, August 19, 2015)

    E - Restore Given a matrix A of size N * N. The rows are numbered from 0 to N-1, the columns are num ...

  4. 【KTU Programming Camp (Day 3)】Queries

    http://codeforces.com/gym/100739/problem/A 按位考虑,每一位建一个线段树. 求出前缀xor和,对前缀xor和建线段树. 线段树上维护区间内的0的个数和1的个数 ...

  5. KTU Programming Camp (Winter Training Day 1)

    A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H

  6. CodeForcesGym 100735G LCS Revised

    LCS Revised Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on CodeForcesGym. O ...

  7. [codeforces 549]G. Happy Line

    [codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...

  8. CodeForces 794 G.Replace All

    CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\), ...

  9. Codeforces 1207 G. Indie Album

    Codeforces 1207 G. Indie Album 解题思路 离线下来用SAM或者AC自动机就是一个单点加子树求和,套个树状数组就好了,因为这个题广义SAM不能存在 \(len[u] = l ...

随机推荐

  1. JQ剪辑图片插件,适用于移动端和PC端

    主要用到以下JS文件: <script src="js/photo/iscroll-zoom.js"></script> <script src=&q ...

  2. Ntdsutil.exe

    Ntdsutil.exe 编辑 本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! Ntdsutil.exe 是一个为 Active Directory 提供管理设施的命令行工具 ...

  3. 设计模式之第6章-迭代器模式(Java实现)

    设计模式之第6章-迭代器模式(Java实现) “我已经过时了,就不要讲了吧,现在java自带有迭代器,还有什么好讲的呢?”“虽然已经有了,但是具体细节呢?知道实现机理岂不美哉?”“好吧好吧.”(迭代器 ...

  4. 【Pow(x,n)】

    题目: Implement pow(x, n). 代码: class Solution { public: double myPow(double x, int n) { double ret = S ...

  5. leetcode 【 Best Time to Buy and Sell Stock 】python 实现

    思路: Say you have an array for which the ith element is the price of a given stock on day i. If you w ...

  6. Wordpress 通过 post id 获取文章 url

    global $post; echo get_permalink($post->ID); 函数详解: Codex - get_permalink() 注意:有些链接是通过 SEO 重定向的,比如 ...

  7. postgresql connection failure:SQLSTATE[08006] [7] could not connect to server: Permission denied Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

    PHP 程序无法连接到 CentOS 上的PostgreSQL,但是在 CentOS 服务器上却能正常运行 psql, 操作如下:多次重启 PG 数据库后发现 CGI 脚本无法连接数据库,但是可以使用 ...

  8. SQL 语句执行后同步返回结果条数

    PgSQL SELECT COUNT(*) OVER() AS res_count FROM table WHERE ... MySQL mysql> SELECT SQL_CALC_FOUND ...

  9. ReentrantLock学习笔记

    参考:https://www.jianshu.com/p/4358b1466ec9 前言: 先来想象一个场景:手把手的进行锁获取和释放,先获得锁A,然后再获取锁B,当获取锁B后释放锁A同时获取锁C,当 ...

  10. iOS-绘制图层-CALayer的属性

    一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position; 用来设 ...