SGU 506 Subsequences Of Substrings
2013-11-23 20:08
309 查看
这个题 还是比较简单的; 把案例 想出来是怎么来的;差不多就出来了; 只要从前往后扫,遇到一个子序列就统计一次,更新起点;
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; char str[112345],cha[112]; int main( ) { while( scanf("%s%s",str+1,cha+1) != EOF ) { int len1 = strlen(str+1); int len2 = strlen(cha+1); int pre = 0; int now = 0; int k = 1; long long res = 0; int i = 1; while( i <= len1 ) { if( str[i] == cha[k] ) { if( k == 1 )now = i; if( k == len2 ) { res += (long long)(now-pre)*(long long)(len1-i+1); k = 1; pre = now; i = now+1; now = 0; }else { i++; k++; } }else i++; } printf("%lld\n",res); } return 0; }
相关文章推荐
- SGU 506.Subsequences Of Substrings
- SGU 506 Subsequences Of Substrings
- [SGU 223]Little Kings(状压DP)
- SGU 103 Traffic Lights
- pku 1226 Substrings
- 二分图判断——sgu 172. eXam
- SGU 110 Dungeon 翻译
- SGU 347 字符串
- SGU118
- SGU 123 The sum
- SGU 333 Random Shooting +数据加强版
- SGU 112 a^b - b^a 大数+二进制优化
- SGU 127 Telephone directory
- SGU102 Coprimes
- [代码]SGU 270 Thimbles
- sgu 176 有源汇的上下界最小流(二分汇源的上界)(好题)
- [SGU]100. A+B
- [SGU]103. Traffic Lights
- sgu 176. Flow construction
- [SGU]107. 987654321 problem