HDU 5791 Two】的更多相关文章

hdu 5791 Two Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1421    Accepted Submission(s): 630 Problem Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequ…
Two 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5791 Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and sequence B' are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not sam…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5791 题目大意: A,B两个数列,问A的子集和B的子集相等的子集对数.子集内顺序按照数列顺序,相同的数字视为不同. 题目思路: [动态规划] f[i][j]表示A前i个数,B前j个数且第j个数必取的值.g[i][j]表示j不一定必取得值. ans=∑f[n][j]. // //by coolxxx //#include<bits/stdc++.h> #include<iostream>…
http://acm.split.hdu.edu.cn/showproblem.php?pid=5791 题意: 给出两个序列,求这两个序列的公共子序列的总个数. 思路: 和LCS差不多,dp[i][j]表示第一个的前i个和第二个的前j个所包含的公共子序列的个数. 首先考虑a[i]≠b[j]的情况,此时应该容易推得dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]. 那么当a[i]=b[j]时,i和j这两个字符可以单独组成一个公共序列,然后前面dp[i-1][…
http://acm.hdu.edu.cn/showproblem.php?pid=5791 Two Problem Description   Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and sequence B' are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not…
Two   Problem Description   Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and sequence B' are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not same. A' is a subsequence of A. B' is a subs…
题意:给两个序列,求公共序列的个数 分析:很自然想到最长公共子序列的转移的转移形式,用dp[i][j]表示第一个串前i个 和第二个串前j个匹配的答案数量,a[i]==b[i],dp[i][j]=dp[i-1][j]+d[i][j-1]+1 a[i]!=b[i],dp[i][j]=dp[i-1][j]+dp[i][j]-1]-dp[i-1][j-1] 代码: #include<bits/stdc++.h> using namespace std; const int maxn=1e3+5; co…
Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' and sequence B' are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not same. A' is a subsequence of A. B' is a subsequence of B. Th…
Two Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 889    Accepted Submission(s): 405 Problem Description Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A' an…
感觉就是最长公共子序列的一个变形(虽然我也没做过LCS啦= =). 转移方程见代码吧.这里有一个要说的地方,如果a[i] == a[j]的时候,为什么不需要像不等于的时候那样减去一个dp[i-1][j-1]呢?其实是要减去的,然后我们注意+1是什么呢?这两个位置是相同的,那么这一对组合是1,然后包含这一个,在dp[i-1][j-1]中相同的又可以拿出来加一遍了,因此就抵消了~ 代码如下: #include <stdio.h> #include <algorithm> #includ…