Codeforces Round #295 (Div. 2) E. Pluses everywhere
来源:互联网 发布:石家庄花都学校 知乎 编辑:程序博客网 时间:2024/06/05 02:09
在n位数之间插入k个+,求所有方式加起来的和mod1e9+7;
考虑各个位上的数对最终结果的贡献,把各个位作为个十百千...位的次数用组合数写出来可以发现规律;
大组合数取模:预处理阶乘和阶乘的逆元,阶乘的逆元可以从后往前递推。
#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<cmath>#include<iomanip>#include<map>#include<algorithm>#include<queue>#include<set>#define inf 1000000000#define pi acos(-1.0)#define eps 1e-8#define seed 131using namespace std;typedef pair<int,int> pii;typedef unsigned long long ULL;typedef long long LL;const int maxn=100005;LL mod=1000000007;LL jiech[maxn];LL rev[maxn];LL sum[maxn];LL r[maxn];char s[maxn];int n,k;LL powMod(LL a,LL m){ if(m==0) return 1; LL ans=powMod(a,m/2);//求逆元 ans=ans*ans%mod; if(m%2==1) ans=ans*a%mod; return ans;}LL C(int n,int m){ if(m>n) return 0; return jiech[n]*rev[n-m]%mod*rev[m]%mod;}int main(){ scanf("%d%d",&n,&k); scanf("%s",s+1); sum[0]=0; for(int i=1;i<=n;i++) sum[i]=sum[i-1]+(s[i]-'0'); jiech[0]=1; r[0]=1; for(int i=1;i<=100000;i++) { jiech[i]=jiech[i-1]*i%mod; r[i]=r[i-1]*10%mod; } rev[100000]=powMod(jiech[100000],mod-2); for(int i=99999;i>=0;i--) { rev[i]=rev[i+1]*(i+1)%mod; } LL res=0; for(int i=1;i<=n;i++) { res=((res+sum[i-1]*r[n-i]%mod*C(i-2,k-1)%mod)%mod+(s[i]-'0')*r[n-i]%mod*C(i-1,k)%mod)%mod; } cout<<res; return 0;}
0 0
- Codeforces Round #295 (Div. 2) E. Pluses everywhere
- #295 (div.2) E.Pluses everywhere
- 【Codeforces】 Codeforces Round #295 (Div. 1) Pluses everywhere
- 【组合数学】 Codeforces Round #295 (Div. 1) C - Pluses everywhere
- Codeforces Round #295 (Div. 1) C. Pluses everywhere
- codeforces 520E Pluses everywhere
- CodeForces 520E Pluses everywhere
- Codeforces Round #295 (Div. 1) C. Pluses everywhere (组合数学+乘法逆元)
- Codeforces 520E. Pluses everywhere 数学
- codeforces 520E Pluses everywhere (数学)
- codeforces 520E Pluses everywhere (数学题)
- Codeforces 520E/521C Pluses everywhere
- Codeforces 520E Pluses everywhere (组合+逆元+规律)
- CodeForces 520E. Pluses everywhere 字符串,组合数学
- Codeforces Round #295 (Div. 2) E
- Codeforces Round #364 div.2 C. They Are Everywhere 【尺追法】
- Codeforces Round #364 (Div. 2) C. They Are Everywhere(二分)
- Codeforces Round #364 (Div. 2)C. They Are Everywhere
- android之Activity的生命周期
- 为什么页游公司喜欢用erlang
- union || union ALL 合并 两个或者多个select语句的结果集
- C链表实现约瑟夫环
- 云购系统、一元云购系统接入短信验证及订单通知功能
- Codeforces Round #295 (Div. 2) E. Pluses everywhere
- 【Unity基础知识④】数据类型,内存大小,数据的范围以及整型
- c++设计模式(桥接模式)
- PyInstaller打包python程序
- iOS开发 - 详谈属性设置readwrite、readonly、retain、copy、assign、nonatomic
- SQL慢查询分析,原因及优化
- vs2013 静态编译Qt和配置方法
- mac 下读写非hid的usb设备
- Linux Shell脚本攻略(一)