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. Apache 的 Rewrite 规则详细介绍

    Rewrite标志: R[=code](force redirect) 强制外部重定向 F(force URL to be forbidden) 禁用URL,返回403HTTP状态码 G(force ...

  2. Nginx启动、停止与平滑重启

    如何启动Nginx:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止Nginx:可以发送向通信号给Nginx主进程的 ...

  3. 不再用.NET框架

    .NET 平台很棒.真的很棒.直到它不再那么棒.我为什么不再用 .NET?简单来说,它限制了我们选择的能力(对我来说很重要),转移了我们的注意力,使得我们向内认知它的安全性,替代了帮助我们认知外面广阔 ...

  4. How to force to Fullscreen Form

    Is it possibile by code resize a form to fullscreen? (like button Maximize) ? // VAR Changed on 10 J ...

  5. openerp 经典收藏 Openerp开发进销存系统完毕总结(转载)

    原文地址:http://blog.csdn.net/heartrude/article/details/9142463 Openerp开发进销存系统完毕总结 分类: 代码历程 OpenERP 工程思想 ...

  6. wpf 仿QQ音乐歌词卡拉OK

    最近用WPF做了个音乐播放器,读取歌词.歌词同步都已经实现了.卡拉OK逐字变色 也实现了,但是逐字变色时不能根据歌手唱的快慢来逐字显示.请问各位大神,这个如何解决,有何思路?(附上我做的界面) 感谢各 ...

  7. 【转载】Powershell在世纪互联Office365中批量将用户添加到组

    $NewUserPath = ".\Office365AddUserToGroup.csv" $NewUsers = import-csv $NewUserPath foreach ...

  8. ASP.NET中利用Split实现对Checkbox的字符串分离放到DataTable里面

    一.背景 昨天唐欢问了我一个问题: 现在有一个CheckBox和一个Label如下图: 要实现选中CheckBox,点击下面打印按钮的时候要做成这个样子的如下图: 简单的说就是档案编号作为表中的一个列 ...

  9. Oracle 10g下载链接

    用迅雷下载: http://download.oracle.com/otn/linux/oracle10g/10201/10201_database_linux_x86_64.cpio.gz http ...

  10. 【Go】为什么用go; Golang Erlang 前世今生

    给自己一条退路,再次比较Erlang和Golang 2014-6-28 陈叶皓 chenyehao@gmail.com 雨天的周末,适合码字的时节... 一年前我开始学习go语言的时候,如获至宝,既有 ...