【链接】 我是链接,点我呀:)

【题意】

让你找到长度为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的更多相关文章

  1. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

  2. 【Codeforces 1036C】Classy Numbers

    [链接] 我是链接,点我呀:) [题意] 让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个. [题解] 只由3个非0数字组成的数字在1~10^18中只有60W个 dfs处理出来之 ...

  3. 【CodeForces 651B】Beautiful Paintings 排序+贪心

    题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...

  4. 【CF55D】Beautiful numbers(动态规划)

    [CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...

  5. 【CF55D】Beautiful numbers

    [CF55D]Beautiful numbers 题面 洛谷 题解 考虑到如果一个数整除所有数那么可以整除他们的\(lcm\),而如果数\(x\)满足\(x\bmod Lcm(1,2...,9)=r\ ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  8. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 746E】Numbers Exchange

    [题目链接]:http://codeforces.com/problemset/problem/746/E [题意] 你有n张卡片,上面写着不同的数字; 然后另外一个人有m张上面写着不同的数字的卡片: ...

随机推荐

  1. 昆石VOS3000_2.1.3.2完整安装包及安装脚本

    安装包下载地址:http://www.51voip.org/post/55.html 安装教程: 上传安装包 核实 关闭selinux 是否关闭 /usr/sbin/sestatus -v cd /r ...

  2. E20170611-hm

    ascending   adj. 上升的,向上的; ascend   vt. 攀登; 继承; 占领;   vi. 上升; 爬坡; 追溯; descending  n. 递减;  descend   v ...

  3. win7安装oracle

    1.下载 2.安装 主目录关键重要

  4. sqlalchemy配置多读写库多连接后的关系设置

    前言 一般来说,解决sqlalchemy 连接多个库的最简单的方式是新建两个或多个db.session 相互没有关联,modle配置不同的db.session来连接,这样的话,relationship ...

  5. eclipse中folder、source folder和package的区别

    今天做ssm项目时,突然发现了这个问题,特别好奇,sqlSessionFactory.xml文件如何找到: 1.放在src/hello目录下: InputStream inputStream = Re ...

  6. iOS基础笔试题 - 集锦一

    前言 下文转载自https://mp.weixin.qq.com/s?__biz=MzA4ODk0NjY4NA==&mid=454115946&idx=1&sn=c7f1b50 ...

  7. CSS知识点整理(1):CSS语法,层叠次序,选择器,其他重要方面。

    1. css的全称 2. CSS的层叠次序:优先级由低到高 ·浏览器设置 ·外部样式表 或者 内部样式表 —— 就近原则 ·内联样式 3. CSS的3种形式,以及每种形式的语法格式 ——注意样式表的为 ...

  8. 解决opencv在pycharm中无代码自动提示的bug

    2018-03-0422:19:39 首先,估计这不是bug 可能是我自己误操作导致的,但是让我搞了好久才搞定,实在是苦恼 如图已实现功能,百度里有很多朋友出现了,这个无代码提示的问题 大概是这样的, ...

  9. Python自动监控错误日志

    平时在查看日志的时候打开满屏的日志,看上去有点凌乱.于是写个Python脚本过滤出想要看的错误的日志.直接上脚本 脚本示例 def read_log(logname,keyword): tell = ...

  10. 【PostgreSQL-9.6.3】LOG: unrecognized configuration parameter "dynamic_shared_memory_type"

    报错如下: 输入如下命令启动PG数据库时,报错: [postgres@drz ~]$ pg_ctl -D /opt/postgresql/data/ start server starting FAT ...