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. php生成txt文件换行问题

    用双引号即"\r\n"换行,不能用单引号即'\r\n'.

  2. 【PHP】phpcms html去除空白

    // 文件路径:/phpcms/libs/classes/template_cache.class.php 42行 // 第四第五行是新增的 $content = $this->template ...

  3. C#项目连接数据库的配置

    一:C# 连接SQL数据库    1.用SqlServer数据库,windows身份验证模式<add name="TestSqlSqever" providerName=&q ...

  4. 使用virtualenv或zc.buildout创建Python-tornado分离环境

    originally created by shuliang under CC BY-NC-ND 3.0 license 一.引言 学习编程,好比练功,总得先有个环境,搭台子是必须的.为了照顾初学者, ...

  5. Error LNK2005 从敌人到朋友

    本人在写学生信息管理系统时遇到一个很头疼的错误——error LNK2005重复定义错误,苦思冥想百度谷歌bing之后都没能解决问题,于一清早刹那间觉得知道问题出在哪儿了,于是乎起床.开机.修改代码一 ...

  6. SVN四部曲之SVN使用详解进阶

    SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...

  7. linux编码

    转: Linux查看文件编码格式及文件编码转换 如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而L ...

  8. 《Power》读书笔记

    原创作品 版权所有 转载请注明出处! 序言 权力是“争”来的,不是“等”来的. 会计.工商管理.营销和销售部门.财务人员(背景).企业咨询小组 在位晋升而竞争的时候,对于公平竞争原则,有些人会采取变通 ...

  9. 【经验】Angularjs 中使用 layDate 日期控件

    layDate 控件地址:http://laydate.layui.com/ 前情:原来系统中使用的日期控件是UI bootstrap(地址:https://angular-ui.github.io/ ...

  10. aes 解密出现 java.lang.NumberFormatException: Invalid int: "ch"

    原因: 将加密/解密的seed 和 加密内容顺序放反.  decrypt(String seed, String encrypted) 附上AES解密/加密代码(android开发): package ...