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 ...
随机推荐
- 68. 对Extjs中store的多种操作
转自:https://www.cnblogs.com/exmyth/archive/2013/05/16/3082045.html 先来个声明,看着不错,贴过来的,没都测试过. Store.getCo ...
- IDEA maven不能下载源码:" can not download source"问题
用IDEA无法下载源码,可以在命令行项目根目录下,执行如下命令 :mvn dependency:resolve -Dclassifier=sources下载 也可以在idea设置中设置为自动下载源码
- Rails 拉数据初始数据库
rails c [1] pry(main)> Scraping.exec
- E20170705-hm
bubble n. 泡,水泡; 冒泡,起泡; 泡影,妄想; (欲表达的) 一点感情;
- js 二叉搜索树
二叉搜索树:顾名思义,树上每个节点最多只有二根分叉:而且左分叉节点的值 < 右分叉节点的值 . 特点:插入节点.找最大/最小节点.节点值排序 非常方便 1 2 3 4 5 6 7 8 9 10 ...
- [Apple开发者帐户帮助]八、管理档案(4)
您可以编辑,下载或删除在开发人员帐户中创建的配置文件.例如,如果您撤消了证书或禁用了配置文件中包含的设备,请编辑配置文件.或重新置备的个人资料,如果因为你它是无效的功能的应用程式服务. 注意: Xco ...
- Boost(1.69.0) windows入门(译)
目录 Boost windows入门 1. 获得Boost源代码 2. Boost源代码组织 The Boost Distribution 3. 仅用头文件的库 Header-Only Librari ...
- 普通平衡树代码。。。Treap
应一些人之邀...发一篇代码 #include <iostream> #include <cstdio> #include <cstdlib> #include & ...
- nginx入门学习
1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了 yum install gcc patch libffi-devel python-devel zlib-devel bzip ...
- ACM_招新笔试题系列——买包子
招新笔试题系列——买包子 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小华刚到大学,一天早上她替她室友买早餐,一共要N个包子. ...