CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence
来源:互联网 发布:cm域名注册 编辑:程序博客网 时间:2024/04/30 00:20
"好久不打codeforces了,本来就极菜!还没感觉!特么被生虐有木有!
这题当div2就出20+,div1早早就500+了,差距啊差距.
吐槽:acm的王道在于可持续装逼,其保证来源于可持续的切题!"
一.题目大意:让你求有多少对pair(x,y),其中x来源于字符串s的"连续子串",y则来源于t字符串的"子序集"
二.被虐原因:当时动规主要纠结于这个"子序集"y如何生成,一直未果,蛋疼!直到看了牛的代码才懂!
三.正解:其实我们可以使用"累加和"的dp方法:见watashi代码咯:
#include <string>#include <iostream>#include <cstdio>using namespace std;const int MAXN = 5050;const long long MOD = 1000000007;long long dp[MAXN][MAXN];string s, t;int main() { freopen("i.txt","r",stdin); int n, m; long long ans = 0; cin >> s >> t; n = s.length(); m = t.length(); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (s[i] == t[j]) { ++dp[i][j]; if (i > 0 && j > 0) { dp[i][j] += dp[i - 1][j - 1]; } } if (j > 0) { dp[i][j] += dp[i][j - 1]; } dp[i][j] %= MOD; //printf("dp[%d][%d]: %d\t",i,j,dp[i][j]); } //cout<<endl; ans += dp[i][m - 1]; } cout << ans % MOD << endl; return 0;}
四.分析:
0.设dp[i][j]是从s串中以i为结尾的"连线字符串"和t串中从t[0...|j|]这个区间的所有pair(x,y)数量.
1.dp[i][j]+=dp[i][j-1],其实就是对以i结尾的子串和t串中[0...|j|]区间的所有对应的累加和!
2.为何强调以i结尾? 因为这是s子串连续的必要保证.从dp[i-1][j-1]抽取结果保证了[0...i]区间中所有以i结尾的"连续子串"的累加和,(共i+1个)
3.ans结果再取累加和:ans += dp[i][m - 1];
五.再吐槽:只能时说我这是就题论题,与大学死记硬背无异!牛们一般系统的理解,基础牢,可能根本不是咱这么想的!我想通过仅的CodeForces来稍提下能力看来是效果不好,因为官方解题报告是俄文,且少!不过我发现,手动模拟大牛们的精简代码于"小规模问题"之上的确是我们这些吊丝领略美的好方法!我反正是信了!
- CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A B C D 构造
- VK Cup 2016 - Round 1 (Div. 2 Edition) C D
- VK Cup 2016 - Round 1 (Div. 2 Edition)-C - Bear and Forgotten Tree 3-构造
- VK Cup 2016 - Round 1 (Div. 2 Edition)C. Bear and Forgotten Tree 3(构造)
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3
- 【VK Cup 2016 - Round 1 (Div 2 Edition)C Bear and Forgotten Tree 3 (构造)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-A. Little Artem and Presents(模拟)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-B. Little Artem and Grasshopper(模拟)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
- Codeforces Croc Champ 2012 - Round 2 (Unofficial Div. 2 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) B.Problems for Round
- 日本武士甲
- 初识Android之简单实例二
- 创建序列
- 编程竞赛常见的问题类型(Programming Contest Problem Types )
- Hives UDF 编写入门
- CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence
- One on One Talk
- ListView 翻页后就没办法点击了 蛋疼了一下午
- 第六周任务1
- poj 1742 Coins
- CSDN社区博客
- NSURLRequest 同步和异步
- 自旋锁spin_lock和raw_spin_lock
- 单选按钮的使用