https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings

DP。注意到以N[i]结尾的每个字符串的子数字和有规律:

5312
5 | 3 53 | 1 31 531 | 2 12 312 5312

sd[2] = 1 + 31 + 531 = 563
sd[3] = 2 + 12 + 312 + 5312
sd[3] = 2 + 10 + 2 + 310 + 2 + 5310 + 2
sd[3] = 4 * 2 + 10 * (1 + 31 + 531 )
sd[3] = (3 + 1) * *N[3]* + 10 * *sd[2]*

sd[i+1] = (i + 2) * N[i] + 10 * sd[i]
sd[0] = N[0]

#include <iostream>
#include <vector>
using namespace std; int main() {
int MOD = 1000000007;
string s;
cin >> s;
int len = s.size();
long long cur_sum = 0;
long long total_sum = 0;
for (int i = 0; i < len; i++) {
cur_sum = (cur_sum * 10 + (s[i] - '0') * (i + 1)) % MOD;
total_sum = (total_sum + cur_sum) % MOD;
}
cout << total_sum << endl;
return 0;
}

  

*[hackerrank]Sam and sub-strings的更多相关文章

  1. Codeforces 452E Three strings 字符串 SAM

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF452E 题意 给定三个字符串 $s1,s2,s3$ ,对于所有 $L ...

  2. CF204E-Little Elephant and Strings【广义SAM,线段树合并】

    正题 题目链接:https://www.luogu.com.cn/problem/CF204E 题目大意 \(n\)个字符串的一个字符串集合,对于每个字符串求有多少个子串是这个字符串集合中至少\(k\ ...

  3. Hacker Rank: Two Strings - thinking in C# 15+ ways

    March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...

  4. HackerRank "Square Subsequences" !!!

    Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...

  5. Tech Stuff - Mobile Browser ID (User-Agent) Strings

    Tech Stuff - Mobile Browser ID (User-Agent) Strings The non-mobile stuff is here (hint: you get jerk ...

  6. 【HDU 4436】 str2int (广义SAM)

    str2int Problem Description In this problem, you are given several strings that contain only digits ...

  7. 【POJ3415】 Common Substrings(后缀数组|SAM)

    Common Substrings Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤ ...

  8. 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings

    E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes inp ...

  9. 后缀自动机(SAM):SPOJ Longest Common Substring II

    Longest Common Substring II Time Limit: 2000ms Memory Limit: 262144KB A string is finite sequence of ...

随机推荐

  1. C# 获取汉字的拼音首字母

    /// <summary> /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 /// </summary> /// <param name="CnS ...

  2. 为msysgit增加vim语法高亮文件

    在win7下装了msysgit,今天我遇到一个不爽的问题,打开git bash,用vim打开一个xml文件 结果都是黑屏的,没语法高亮,这个必须不能忍啊,我找到msysgit的安装目录,发现Vim73 ...

  3. CLR via C# 混合线程同步构造

    1. 自旋,线程所有权和递归 2. 混合构造 a.ManualResetEventSlim b.SemaphoreSlim c.Monitor d.ReaderWriterLockSlim 3.条件变 ...

  4. DataSnap数据库连接池,数据集对象池的应用

    传统的应用服务器的开发往往是在ServerMethods单元中拖放一堆TDataSet, TDaTaSetProvider控件,这是一个最简单粗暴的开发方向,往往会造成服务端程序文件的臃肿.服务运行期 ...

  5. glibc学习介绍篇

    C语言自身并没有提供IO,内存管理,字符串操作等类似的机制.作为弥补,C语言有一个标准库帮助C语言实现这些机制.我们在编译C程序的时候基本上都需要链接到这些库文件. GNU C Library定义IS ...

  6. Java HTML页面抓取实例

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  7. redis 界面软件使用

    ubuntu 下下载安装包 sudo dpkg -i redis-desktop-manager_0.8.3-120_amd64.deb//安装 redis-desktop-manager //启动

  8. topcoder 673

    DiV1 300:给一组士兵再给一组战马都有权值. 安排战马的顺序的方案数,是第一个士兵和其战马的权值乘积最大. 做法:随便暴力就好. 枚举战马和第一个士兵匹配.其他士兵按权值从大到小排序,战马权值按 ...

  9. centos wordpress

    How To Install Linux, nginx, MySQL, PHP (LEMP) stack on CentOS 6 https://www.digitalocean.com/commun ...

  10. hbase meta表修复

    meta表修复一 查看hbasemeta情况hbase hbck1.重新修复hbase meta表(根据hdfs上的regioninfo文件,生成meta表)hbase hbck -fixMeta2. ...