CodeForcesGym 100735G LCS Revised
LCS Revised
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
101010
3
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
char str[maxn];
int main() {
while(~scanf("%s",str)) {
int one = ,zero = ;
for(int i = ; str[i]; ++i)
if(str[i] == '') zero++;
else one++;
printf("%d\n",min(zero,one));
}
return ;
}
CodeForcesGym 100735G LCS Revised的更多相关文章
- 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 ... 
- 我的第一篇博客----LCS学习笔记
		LCS引论 在这篇博文中,博主要给大家讲一个算法----最长公共子序列(LCS)算法.我最初接触这个算法是在高中学信息学竞赛的时候.那时候花了好长时间理解这个算法.老师经常说,这种算法是母算法,即从这 ... 
- 动态规划之最长公共子序列(LCS)
		转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ... 
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
		1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ... 
- Hackerrank11  LCS Returns 枚举+LCS
		Given two strings, a and , b find and print the total number of ways to insert a character at any p ... 
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
		UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ... 
- 删除部分字符使其变成回文串问题——最长公共子序列(LCS)问题
		先要搞明白:最长公共子串和最长公共子序列的区别. 最长公共子串(Longest Common Substirng):连续 最长公共子序列(Longest Common Subsequence,L ... 
- 最大公共字串LCS问题(阿里巴巴)
		给定两个串,均由最小字母组成.求这两个串的最大公共字串LCS(Longest Common Substring). 使用动态规划解决. #include <iostream> #inclu ... 
- LCS
		/**LCS问题*/ #include <iostream>#include <string>#include <algorithm> using namespac ... 
随机推荐
- bzoj1009 [HNOI2008]GT考试——KMP+矩阵快速幂优化DP
			题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1009 字符串计数DP问题啊...连题解都看了好多好久才明白,别提自己想出来的蒟蒻我... 首 ... 
- JSP-Runoob:JSP 表达式语言
			ylbtech-JSP-Runoob:JSP 表达式语言 1.返回顶部 1. JSP 表达式语言 JSP表达式语言(EL)使得访问存储在JavaBean中的数据变得非常简单.JSP EL既可以用来创建 ... 
- Systick 更新
			之前写的systick_config(loadvalue) 根据系统时钟为72Mhz来写的,如果system clock不是72MHz怎么办? 重新写了一下,先获取,系统时钟频率. //参数为ms v ... 
- windows 7系统下安装SQL Server 2005图文教程
			由于工作需要,今天要在电脑上安装SQL Server 2005.以往的项目都是使用Oracle,MS的数据库还真的没怎么用过,安装Oracle已经轻车熟路,但装SQL Server好像还有点小麻烦,所 ... 
- WP处理事件
			(1).Launching事件 Launching(进入)事件是每一个第三方应用在第一次运行时都必须执行的事件,它主要负责应用程序的初始化.这个事件与Closing事件是对应的,一个运行正常的应用程序 ... 
- E20170930-hm
			parse vt. 从语法上描述或分析(词句等); 
- [Swift通天遁地]六、智能布局-(1)给视图添加尺寸和中心点的约束
			★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ... 
- Java数组去重(利用数组,不借助集合)
			今天有个同学问我说老师,Java里边数组怎么去重,在不借助List集合的情况下,最后呢我整理了一下,打算发一篇博文,希望能帮助到有用的人,大佬绕过 public static void arrUniq ... 
- openpyxl python操作Excel表格,
			这里openpyxl只支持xlsx格式的Excel,openpyxl使用起来会更方便一些,所以如果只操作小流水线文件的话,那么可以优先选择openpyxl,如果要兼容xls的话,就使用xlrd/xlw ... 
- [转]sed常用命令总结
			转自:http://blog.chinaunix.net/uid-26963748-id-3249732.html 一.Sed简介 Sed:Stream Editor 流式编辑器 又称行编辑器,每次 ... 
