Codeforces Round #675 (Div. 2) C - Bargain (推导)
程序员文章站
2022-06-05 13:46:57
...
给你一串字符串,从里面删1~n长度的子串之后,剩下的可能得数字的和。
比如107,删1,0,7,10,07,107之后剩07,17,10,7,1,0(空串)
枚举每个字符串,考虑这一位留下来对答案的总贡献
该位的贡献可分为:删除的区间在该位之前的贡献和删除的区间在该位之后的贡献
#define int ll
const int mod=1e9+7;
int f[MX];
void init(int n)
{
f[0]=0,f[1]=1;
ll tag=10;
for(int i=2;i<=n;++i)
f[i]=(f[i-1]+i*tag%mod)%mod,tag=tag*10%mod;
}
void solve()
{
string s;cin>>s;
reverse(all(s));
int n=s.size()-1;
init(n);
ll ans=0,tag=1;
rep(i,s.size())
{
int d=s[i]-'0';
ll tmp1=(n-i)*(n-i+1)/2%mod*tag%mod*d%mod;
tmp1%=mod;
ll tmp2 = d*f[i]%mod;
ans=((ans+tmp1)%mod+tmp2)%mod;
tag=tag*10%mod;
}
cout<<ans<<endl;
}
上一篇: Java对json和jsonarray字符串的解析
下一篇: 虚基类
推荐阅读
-
Codeforces Round #649 (Div. 2) C-Ehab and Prefix MEXs
-
Codeforces Round #432 (Div. 2) - C - Five Dimensional Points
-
Codeforces Round #658 (Div. 2)C1. Prefix Flip (Easy Version)(贪心)
-
Codeforces Round #658 (Div. 2) (C1、C2)
-
Codeforces Round #320 (Div. 2) C. A Problem about Polyline ( 数学 )
-
Codeforces Round #659 (Div. 2) C、String Transformation 1(思维+set)
-
Codeforces Round #654 (Div. 2)-C. A Cookie for You
-
Educational Codeforces Round 85 (Rated for Div. 2) C. Circle of Monsters(前缀和 预处理 贪心)
-
Codeforces Round #651 (Div. 2) C. Number Game
-
Codeforces Round #666 (Div. 2)C - Multiples of Length(错位相减)