C. Bargain(贡献法+组合数学)

https://codeforces.com/problemset/problem/1422/C


思路:

对于i这个位,通过组合讨论的方式看他的贡献。

如果是i的左边,那么前面任取一段连续的区间可能数为1/2*(i-1)*i*str[i];

如果是i右边,那么这个x是取的连续长度,(n-i-x+1)是该长度的取法

然后令t=n-i-x进行转化。

然后预处理两个数组。

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL p[maxn],f[maxn];
char str[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  cin>>(str+1);
  LL n=strlen(str+1);
  p[0]=1;
  for(LL i=1;i<maxn-10;i++) p[i]=p[i-1]*10%mod;
  f[0]=1;
  for(LL i=1;i<maxn-10;i++){
    f[i]=(f[i-1]%mod+(i+1)%mod*p[i]%mod)%mod;
  }
  LL ans=0;
  for(LL i=1;i<=n;i++){
    LL t1=(i*(i-1)/2%mod*(str[i]-'0')%mod*p[n-i])%mod;
    LL t2=(str[i]-'0')*f[n-i-1]%mod;
    ans=(ans%mod+t1%mod+t2%mod )%mod;
  }
  cout<<ans%mod<<"\n";
return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值