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
101010
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 【KTU Programming Camp (Day 3)】Queries
http://codeforces.com/gym/100739/problem/A 按位考虑,每一位建一个线段树. 求出前缀xor和,对前缀xor和建线段树. 线段树上维护区间内的0的个数和1的个数 ...
- KTU Programming Camp (Winter Training Day 1)
A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H
- CodeForcesGym 100735G LCS Revised
LCS Revised Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on CodeForcesGym. O ...
- [codeforces 549]G. Happy Line
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love ...
- CodeForces 794 G.Replace All
CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\), ...
- Codeforces 1207 G. Indie Album
Codeforces 1207 G. Indie Album 解题思路 离线下来用SAM或者AC自动机就是一个单点加子树求和,套个树状数组就好了,因为这个题广义SAM不能存在 \(len[u] = l ...
随机推荐
- 动态规划:HDU3496-Watch The Movie(二维费用的背包问题)
Watch The Movie Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- spring-data-mongodb
[引入maven依赖] <!-- mongodb spring --> <dependency> <groupId>org.springframework. ...
- spark 对hbase 操作
本文将分两部分介绍,第一部分讲解使用 HBase 新版 API 进行 CRUD 基本操作:第二部分讲解如何将 Spark 内的 RDDs 写入 HBase 的表中,反之,HBase 中的表又是如何以 ...
- 1022: [SHOI2008]小约翰的游戏John9(Auti_SG)
1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 3150 Solved: 2013[Submit] ...
- SQL语句Not IN优化方案
总结网友们在CSDN社区上对于not in的优化策略,整理如下,备查. select * from emp where emp_no not in (select emp_no from emp ...
- IOS开发学习笔记038-autolayout 自动布局 界面实现
在storyboard/xib文件中实现自动布局 autolayout 1.注意事项 autolayout和frame属性是有冲突的,所以如果准备使用autolayout,就不要再代码中对控件的fra ...
- 设计模式 uml元素
uml的构造包含3种 事物4种:结构,行为,分组,注释事物 关系4种:泛化,实现,依赖,关联, 图10种,用例图,类图,对象,包,组件,部署,状态,活动,序列,协作 事物是对模型中最具代表性的成分的抽 ...
- schema.xml属性概念
# schema 定义逻辑库 checkSQLschema 当该值设置为 true 时,如果我们执行语句**select * from TESTDB.travelrecord;**则 MyCat 会 ...
- CSS查缺补漏篇
前面的话:关于CSS,之前我已经做过一些基础的知识点介绍.CSS主要是用来给页面设置样式的,一般说来,在一个网站中,CSS应该独立封装在一个单独的.css外部文件中.样式的设置总体来说是不难的,但是需 ...
- “取出数据表中第10条到第20条记录”的sql语句+selecttop用法
1.首先,select top用法: 参考问题 select top n * from和select * from的区别 select * from table -- 取所有数据,返回无序集合 sel ...