CodeForces 163A Substring and Subsequence(DP)
来源:互联网 发布:标签编辑软件 编辑:程序博客网 时间:2024/06/06 10:40
题意:给你两个字符串,然后问你第一个字符串的子串和第二个子序列有多少对相同的串
思路:dp[i][j]表示第一个串以i结尾,第二个串以j结尾的方案数,最简单的dp就是dp[i][j]=1+dp[i-1][j-1]+dp[i-1][j-2]+....+dp[i-1][1],然后把前面的弄成前缀和就可以了
#include<bits/stdc++.h>using namespace std;#define LL long longconst int maxn = 5005;const int mod = 1e9+7;int dp[maxn][maxn];char a[maxn],b[maxn];int main(){scanf("%s%s",a+1,b+1);int len1 = strlen(a+1);int len2 = strlen(b+1);for (int i = 1;i<=len1;i++){for (int j = 1;j<=len2;j++){if (a[i]==b[j])dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;}}LL ans = 0;for (int i = 1;i<=len1;i++)ans = (ans+dp[i][len2])%mod;printf("%lld\n",ans);}
0 0
- CodeForces 163A Substring and Subsequence(DP)
- codeforces 163A A. Substring and Subsequence(dp)
- CodeForces 163A - Substring and Subsequence 类LCS的DP
- CF 163 A Substring and Subsequence(dp)
- codeforces 163A Substring and Subsequence (dp,最长公共子串变形)
- Codeforces 766 C Mahmoud and a Message 详解(DP)
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
- Codeforces 766A Mahmoud and Longest Uncommon Subsequence
- codeforces 766 A Mahmoud and Longest Uncommon Subsequence
- Codeforces 766A-Mahmoud and Longest Uncommon Subsequence
- codeforces 766A Mahmoud and Longest Uncommon Subsequence
- Codeforces-873B:Balanced Substring(DP)
- Codeforces 414A Mashmokh and ACM(dp)
- Codeforces 588A Duff and Meat 【dp】
- CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence
- codeforces CodeForces 204A Little Elephant and Interval (数位dp简单)
- A and B and Interesting Substrings - CodeForces 519 D dp
- arm汇编指令bne、beq和tst
- 初探OpenStack Mitaka
- [ERROR] No plugin found for prefix 'jetty' in the current project and in the plu gin groups [org.apa
- AndroidStudio中如何使用Git和Github管理项目
- 芒果iOS开发之AFNetworking3.0.4使用指南
- CodeForces 163A Substring and Subsequence(DP)
- thinkphp多语言切换
- Android之Button自定义点击效果
- LeetCode Algorithms #172 <Factorial Trailing Zeroes>
- VS上jpeg编码程序移植到DSP的总结
- 关于博客的一点点想法
- 充分发挥异步在 ASP.NET 中的强大优势
- git数据流
- 同步和异步,阻塞和非阻塞