Codeforces 163A Substring and Subsequence】的更多相关文章

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?mobile=true 题目大意:给出两个串,问a的连续子串和b的子串(可以不连续)相同的个数. 思路:在LCS上加点改动 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> ; ],b[]; ][]; int read(){…
题目链接: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]…
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…
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…
919D - Substring 思路: 拓扑排序判环+DAG上dp+记忆化搜索 状态:dp[i][j]表示以i为起点的路径中j的最大出现次数 初始状态:dp[i][j]=1(i have no son && w[i]==j) dp[i][j]=0(i have no son && w[i]!=j) 状态转移:dp[i][j]=max(dp[t][j])(t is i's son) dp[i][j]++(w[i]==j) 代码: #include<bits/stdc+…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so th…
题目:Substring 题意:给你一个有向图, 一共有n个节点 , m条变, 一条路上的价值为这个路上出现过的某个字符最多出现次数, 现求这个最大价值, 如果价值可以无限大就输出-1. 题解:当这个有向图构成一个环的时候就会使得值无限大,所以先用拓扑排序判断一下有没有环,如果有环直接输出-1, 如果没有环就再使用树形dp并记忆化存数,来找到最大值. 代码: #include<cstring> #include<iostream> using namespace std; +; s…
<题目链接> 题目大意:有一个具有n个节点,m条边的有向图,每个点对应一个小写字母,现在给出每个顶点对应的字母以及有向边的连接情况,求经过的某一条路上相同字母出现的最多次数.如果次数无限大(出现环),则输出-1. 解题分析: 因为是有向图并且是对完整路径进行操作,所以我们能够想到拓扑排序,同时拓扑排序也能够比较方便地判环.现在就是考虑如何得到路径中出现次数最多的字母个数,我们对每个节点,维护一个dp[u][j],表示u节点在所有通过u的道路中,截止到u节点,j 字母所出现的最大个数(其实就是最…
题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结果上分别对26个字母dp求出最大结果,并取最大值(一定要分别对每个字母dp,否则会出现问题). #include<bits/stdc++.h> using namespace std; ; int N,M; vector<int> G[maxn]; vector<int>…