【Codeforces 300C】Beautiful Numbers
【链接】 我是链接,点我呀:)
【题意】
让你找到长度为n的数字
这个数字只由a或者b组成
且这n个数码的和也是由a或者b组成的
求出满足这样要求的数字的个数
【题解】
枚举答案数字中b的个数为y,那么a出现的个数就为n-y
那么和就是n*a + (b-a)*y;
这个数字最多就7位的样子
很容易检查是不是只包含a或者b
然后如果满足只包含a或者b
则答案加上C(n,y)
即n个位置中选择y个放b,其他的放a
组合数取余的话,预处理一下阶乘以及阶乘的逆元就好
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)1e6;
static class Task{
long MOD = (int)1e9+7;
int a,b,n;
long fac[],rfac[];
long _pow(long x,long y) {
long ans = 1;
while (y>0) {
if (y%2==1) ans = (ans * x)%MOD;
x = (x*x)%MOD;
y/=2;
}
return ans;
}
long C(int n,int m) {
//n!/((n-m)!*m!)
if (n<m) return 0;
long temp1 = fac[n];
temp1 = temp1*rfac[n-m]%MOD;
temp1 = temp1*rfac[m]%MOD;
return temp1;
}
boolean ok(int x) {
if (x==0) return false;
while (x>0) {
int temp = x%10;
if (temp!=a && temp!=b) return false;
x = x/10;
}
return true;
}
public void solve(InputReader in,PrintWriter out) {
fac = new long[N+10];
rfac = new long[N+10];
fac[0] = 1;
for (int i = 1;i <= N;i++) fac[i] = fac[i-1]*i%MOD;
rfac[N] = _pow(fac[N],MOD-2 );
for (int i = N-1;i >= 0;i--) {
rfac[i] = rfac[i+1]*(i+1)%MOD;
}
a = in.nextInt();b = in.nextInt();n = in.nextInt();
long ans = 0;
for (int y = 0;y <= n;y++) {
//b有y个
int sumdigits = n*a + (b-a)*y;
if (ok(sumdigits)) {
ans = ans + C(n,y);
ans = ans % MOD;
}
}
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 300C】Beautiful Numbers的更多相关文章
- 【数位dp】Beautiful Numbers @2018acm上海大都会赛J
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...
- 【Codeforces 1036C】Classy Numbers
[链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...
- 【CodeForces 651B】Beautiful Paintings 排序+贪心
题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- 【CF55D】Beautiful numbers
[CF55D]Beautiful numbers 题面 洛谷 题解 考虑到如果一个数整除所有数那么可以整除他们的\(lcm\),而如果数\(x\)满足\(x\bmod Lcm(1,2...,9)=r\ ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- 【66.47%】【codeforces 556B】Case of Fake Numbers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 746E】Numbers Exchange
[题目链接]:http://codeforces.com/problemset/problem/746/E [题意] 你有n张卡片,上面写着不同的数字; 然后另外一个人有m张上面写着不同的数字的卡片: ...
随机推荐
- 4-3 买家类目-service
DAO:ProductCategory.Service可以简化一些,叫CategoryService. package com.imooc.sell.service; import com.imooc ...
- Yii2笔记一
环境LNMP,通过Composer安装 安装Composer(已经安装请跳过) curl -s http://getcomposer.org/installer | php #php可执行文件所在位置 ...
- bzoj2093: [Poi2010]Frog(单调队列,倍增)
2093: [Poi2010]Frog Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 568 Solved: 186[Submit][Status] ...
- phpAnalysis调试接口
phpAnalysis是一款轻量级非侵入式PHP应用性能分析器,适用于开发.测试及生产环境部署使用,方便开发及测试工程师诊断性能问题: 通过tideways收集PHP程序单步运行过程中所有的函数调用时 ...
- CentOS环境下下调整home和根分区大小
项目建设方给提供了3台CentOS的服务器,连接进去之后发现磁盘空间很大,但是都放在了home目录下,所以需要调整一下. 1.查看磁盘使用情况 [root@CentOS ~]# df -h Files ...
- Hadoop Hive概念学习系列之hive的索引及案例(八)
hive里的索引是什么? 索引是标准的数据库技术,hive 0.7版本之后支持索引.Hive提供有限的索引功能,这不像传统的关系型数据库那样有“键(key)”的概念,用户可以在某些列上创建索引来加速某 ...
- CF822C Hacker, pack your bags!
思路: 对于一个区间[l, r],只需枚举所有满足r' < l并且二者duration之和为x的区间[l', r'],寻找其中二者cost之和最小的即可.于是可以开一个数组a[],a[i]表示所 ...
- 1682. [HAOI2014]贴海报
1682. [HAOI2014]贴海报 ★★☆ 输入文件:ha14d.in 输出文件:ha14d.out 简单对比 时间限制:1 s 内存限制:256 MB [题目描述] Byteto ...
- (9)string对象上的操作2
比较string对象的比较运算符 这种由string类定义的几种比较字符串的运算符能逐一比较string对象中的字符(对大小写敏感).
- 42使用NanoPiM1Plus在Android4.4.2下的录音测试
42使用NanoPiM1Plus在Android4.4.2下的录音测试 大文实验室/大文哥壹捌陆捌零陆捌捌陆捌贰21504965 AT qq.com完成时间:2017/12/5 17:51版本:V1. ...