Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers
题目连接:
http://www.codeforces.com/contest/300/problem/C
Description
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number.
For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't.
Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109 + 7).
A number's length is the number of digits in its decimal representation without leading zeroes.
Input
The first line contains three integers: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 106).
Output
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Sample Input
1 3 3
Sample Output
1
Hint
题意
给你 a,b,n
问你有多少个长度为n的数中只含有a,b
并且这个数的每一个数位之和的数,也只含有a,b
题解:
直接暴力枚举和就好了,然后check
如果可行的话,他的贡献为C(n,i)
C(n,i)用逆元来做就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
#define maxn 1000005
long long fac[maxn];
int a,b,n;
long long qpow(long long a,long long b)
{
long long ans=1;a%=mod;
for(long long i=b;i;i>>=1,a=a*a%mod)
if(i&1)ans=ans*a%mod;
return ans;
}
long long C(long long n,long long m)
{
if(m>n||m<0)return 0;
long long s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-2)%mod;
}
int check(long long x)
{
while(x)
{
if(x%10!=a&&x%10!=b)return 0;
x/=10;
}
return 1;
}
int main()
{
fac[0]=1;
for(int i=1;i<maxn;i++)
fac[i]=fac[i-1]*i%mod;
scanf("%d%d%d",&a,&b,&n);
long long ans = 0;
for(int i=0;i<=n;i++)
{
long long num = a*i+b*(n-i);
if(check(num))
ans = (ans+C(n,i))%mod;
}
cout<<ans<<endl;
}
Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力的更多相关文章
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of ...
- Codeforces Round #604 (Div. 2) B. Beautiful Numbers(双指针)
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #558 (Div. 2)C(计算几何,排列组合,模拟)
#include<bits/stdc++.h>using namespace std;typedef struct{ double k,b;}node;node k[1000007];bo ...
- 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...
- Codeforces Round #181 (Div. 2)
A. Array 模拟. B. Coach 模拟. C. Beautiful Numbers good number的位和最大不超过\(10^7\),那么只要枚举a或b的个数,然后最多循环7次判断位和 ...
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest
链接: https://codeforces.com/contest/1265/problem/C 题意: So the Beautiful Regional Contest (BeRC) has c ...
- Codeforces Round #181 (Div. 2) B. Coach 带权并查集
B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n ...
随机推荐
- OFBIZ+ECLIPSE
1. 首先要安装好OFBIZ,参考<OFBIZ安装>. 2. 安装ECLIPSE. 3. 安装FreeMarker插件,这是OFBIZ的模版引擎.在"Eclipse Market ...
- 给编译好的DLL增加签名
两个步骤,记录如下,主要用在silverlight中引用的dll要签名时: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm ...
- no symbol version for module_layout
内核模块编译helloworld: no symbol version for module_layout, 尝试各种解决办法, 都没搞定, 版本也是对的. dmesg提示no symbol vers ...
- Tilera 服务器上OpenJDK的安装尝试
一.起因 这两天比较有意思,客户那里的代码遇到了一个jvm的bug崩溃了,所以老板让我升级JVM,这是一个处理器架构和x86不同的处理器,我改怎么安装呢? 我百度了OpenJDK,并且按照http:/ ...
- 基于MapReduce的矩阵乘法运算
1.采用两个MapReduce运算串联来实现 Pik= Mij*Njk 第一步: Map函数:将每个矩阵运算mij传给键值对(j,(M,i,mij)),将每个矩阵元素njk传给键值对(j,(N,k,n ...
- [转载]关于CSDN, cnblog, iteye和51cto四个博客网站的比较与分析
CSDN:http://blog.csdn.net/ cnblog: http://www.cnblogs.com/ iteye: http://www.iteye.com/blogs/ 51cto: ...
- 在使用EF开发时候,遇到 using 语句中使用的类型必须可隐式转换为“System.IDisposable“ 这个问题。
原因就是 这个程序集中没有引用EntityFramework.可以使用Nuget 安装EntityFramewok.
- SharePoint咨询师之路:设计之前的那些事二:规模
提示:本系列只是一个学习笔记系列,大部分内容都可以从微软官方网站找到,本人只是按照自己的学习路径来学习和呈现这些知识. 有些内容是自己的经验和积 累,如果有不当之处,请指正. 咨询师更多的时候是解决方 ...
- 全文索引之nutch与hadoop(转)
原文:http://blog.csdn.net/chaofanwei/article/details/39476535 全文索引-lucene,solr,nutch,hadoop之lucene 全文索 ...
- iis 支持html执行php输出
iis 支持html执行php输出 2012-07-25 10:50:23| 分类: PHP|举报|字号 订阅 在HTML中有个简单的的PHP随机数需要输出,例如: <td backg ...