A. Substring and Subsequence 题目连接: http://codeforces.com/contest/163/problem/A Description One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately w…
题目链接:http://codeforces.com/problemset/problem/163/A 题意: 给你两个字符串a,b,问你有多少对"(a的子串,b的子序列)"可以匹配. 题解: 表示状态: dp[i][j] = pairs a的子串以a[i]结尾,b的子序列以b[1 to j]结尾的方案数. 找出答案: ans = ∑ dp[i][lb] (la,lb代表a和b的长度) 如何转移: dp[i][j] = dp[i][j-1] if(a[i] == b[j]) dp[i]…
http://codeforces.com/problemset/problem/163/A?mobile=true 题目大意:给出两个串,问a的连续子串和b的子串(可以不连续)相同的个数. 思路:在LCS上加点改动 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> ; ],b[]; ][]; int read(){…
A. Substring and Subsequence   One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, s…
题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结果上分别对26个字母dp求出最大结果,并取最大值(一定要分别对每个字母dp,否则会出现问题). #include<bits/stdc++.h> using namespace std; ; int N,M; vector<int> G[maxn]; vector<int>…
Substring and Subsequence 题意 给出两个字符串s,t,求出有多少对s的子串和t的子序列相等. 思路 类似于最长公共子序列的dp数组. dp[i][j]表示s中以i为结尾的子串和t中前j个的子序列相等的个数. 转移的时候dp[i][j]=dp[i][j-1];. 如果s[i]==t[j]那么dp[i][j]+=dp[i-1][j-1]+1;,1是s[i]自身作为子串的情况. 最后统计dp[i][lent]的和 代码 #include<bits/stdc++.h> #de…
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权值为i的二叉树的个数. 两棵树不同当且仅当树的形态不一样或者是树的某个点的点权不一样 分析 设\(c(i)\)表示数值i是否在集合中.\(f(i)\)表示权值为i的二叉树的个数.那么 \[f(n)=\sum_{i=1}^n c(i) \sum_{j=0}^{n-i} f(j)f(n-i-j)\] 其…
D. Longest Subsequence 题目连接: http://www.codeforces.com/contest/632/problem/D Description You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM a…
Bracket Substring 这么垃圾的题怎么以前都不会写啊, 现在一眼怎么就会啊.... 考虑dp[ i ][ j ][ k ][ op ] 表示 已经填了 i 个空格, 末尾串匹配到 所给串的 第 j 个, 已经放了 k 个左括号, 是否存在所给串的方案数. 因为不匹配的不是从头开始的, 所以暴力求下一个或者直接ac自动机都可以. #include<bits/stdc++.h> #define LL long long #define LD long double #define u…
You are given an integer array of length nn. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to […