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. 转:Java HashMap实现详解

    Java HashMap实现详解 转:http://beyond99.blog.51cto.com/1469451/429789 1.    HashMap概述:    HashMap是基于哈希表的M ...

  2. 【Qt】Qt之自定义搜索框【转】

    简述 关于搜索框,大家都经常接触.例如:浏览器搜索.Windows资源管理器搜索等. 当然,这些对于Qt实现来说毫无压力,只要思路清晰,分分钟搞定. 简述 效果 细节分析 Coding 源码下载 效果 ...

  3. html5离线应用详摘

    html5离线应用详摘 在html文件里配置如下: <html manifest=”name.manifest”> 在name.manifest文件里配置如下: CACHE MANIFES ...

  4. php威盾解密的例子分享

    例子,批量解密  代码如下 复制代码 <?php/************************************威盾PHP加密专家解密算法 By:zhrt*http://www.111 ...

  5. Ant之build.xml

    转载地址:http://www.cnblogs.com/clarkchen/archive/2011/03/10/1980194.html http://lisongqiu168.iteye.com/ ...

  6. Activity的Launch mode详解 singleTask正解

    Activity有四种加载模式:standard(默认), singleTop, singleTask和 singleInstance.以下逐一举例说明他们的区别: standard:Activity ...

  7. CentOS 6.3 配置 yum

    ContOS 配置yum:1.cd /etc/yum.repos.d2.创建个任意目录,将所有文件移动到创建的目录中,除了CentOS-Media.repo3.编辑CentOS-Media.repov ...

  8. MySQL 库大小、表大小、索引大小查询命令

    1.进去指定schema 数据库(存放了其他的数据库的信息)     mysql> use information_schema; 2.查询所有数据的大小      mysql> sele ...

  9. [SQL_Server_Question]Msg 1105无法为数据库 'tempdb' 中的对象分配空间,因为 'PRIMARY' 文件组已满

    错误消息: Msg 1105, Level 17, State 2, Line 266Could not allocate space for object 'dbo.Large Object Sto ...

  10. php将数据库导出成excel的方法

    <?php $fname = $_FILES['MyFile']['name']; $do = copy($_FILES['MyFile']['tmp_name'],$fname); if ($ ...