*[hackerrank]Sam and sub-strings
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的更多相关文章
- Codeforces 452E Three strings 字符串 SAM
原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF452E 题意 给定三个字符串 $s1,s2,s3$ ,对于所有 $L ...
- CF204E-Little Elephant and Strings【广义SAM,线段树合并】
正题 题目链接:https://www.luogu.com.cn/problem/CF204E 题目大意 \(n\)个字符串的一个字符串集合,对于每个字符串求有多少个子串是这个字符串集合中至少\(k\ ...
- Hacker Rank: Two Strings - thinking in C# 15+ ways
March 18, 2016 Problem statement: https://www.hackerrank.com/challenges/two-strings/submissions/code ...
- HackerRank "Square Subsequences" !!!
Firt thought: an variation to LCS problem - but this one has many tricky detail. I learnt the soluti ...
- 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 ...
- 【HDU 4436】 str2int (广义SAM)
str2int Problem Description In this problem, you are given several strings that contain only digits ...
- 【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≤ ...
- 字符串(后缀自动机):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 ...
- 后缀自动机(SAM):SPOJ Longest Common Substring II
Longest Common Substring II Time Limit: 2000ms Memory Limit: 262144KB A string is finite sequence of ...
随机推荐
- 转:Apache与Nginx的优缺点比较
Apache与Nginx的优缺点比较 http://weilei0528.blog.163.com/blog/static/206807046201321810834431/ 1.nginx相对于ap ...
- MongoDB的分组统计 group
mongodb中的分组聚合用$group,而且处理的最大数据量为100M如果超出需要写入到磁盘,使用格式如下: { $group: { _id: <expression>, <fie ...
- Hello,cnblog。
This my blog
- PHP安全之register_globals
一.register_globals = Off 和 register_globals = On的区别 register_globals是php.ini里的一个配置,这个配置影响到php如何接收传递过 ...
- robots.txt文件配置和使用方法详解
robots.txt文件,提起这个概念,可能不少站长还很陌生:什么是robots.txt文件?robots.txt文件有什么作用?如何配置robots.txt文件?如何正确使用robots.txt文件 ...
- TextView中gravity属性值测定
Attributes Explain top 不改变控件大小,对齐到容器顶部 bottom 不改变控件大小,对齐到容器底部 left 不改变控件大小,对齐到容器左侧 right 不改变控件大小,对齐到 ...
- perl中shift 和unshift 操作
##################################################################### unshift 和shift 对一个数组的开头进行操作(数组 ...
- apache配置VirtualHost(windows)
以下方式适合原生 Apache, XAMPP 和WAMP 套件. 1. 打开目录 {Apache2 安装目录}\conf\extra\, 找到 httpd-vhosts.conf 文件. 2. 仿照例 ...
- Project Settings -> Editor 设置详解
Default Behavior Mode (默认行为模式) 定义项目在导入Assets时的默认导入设置,当设置为3D模式时,Unity假设将导入的文件创建为纹理类型(如:PNG文件):当设置为2D时 ...
- UML 小结(5)- 图解 Rational Rose 的详细安装过程
在学习UML的时候,会用到画图工具:Rotional Rose . 原以为这款软件直接下载下来或者跟朋友那边拷过来就可以直接用了,结果却是没有那么简单,如果读者您也是为了解决这个家伙的安装问题的话,那 ...