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

【题意】

让你找到长度为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. 【废弃】【WIP】JavaScript Object

    创建: 2017/11/03 废弃: 2019/02/19 重构此篇.原文归入废弃  增加[废弃中]标签与总体任务 结束: 2019/03/03 完成废弃, 删除[废弃中]标签, 添加[废弃]标签 T ...

  2. bzoj 1620: [Usaco2008 Nov]Time Management 时间管理【贪心】

    按s从大到小排序,逆推时间模拟工作 #include<iostream> #include<cstdio> #include<algorithm> using na ...

  3. bzoj 1634: [Usaco2007 Jan]Protecting the Flowers 护花【贪心】

    因为交换相邻两头牛对其他牛没有影响,所以可以通过交换相邻两头来使答案变小.按照a.t*b.f排降序,模拟着计算答案 #include<iostream> #include<cstdi ...

  4. http2及server push

      本文主要研究下java9+springboot2+undertow2启用http2及server push maven <parent> <groupId>org.spri ...

  5. G - And Then There Was One (约瑟夫环变形)

    Description Let’s play a stone removing game. Initially, n stones are arranged on a circle and numbe ...

  6. 381 Insert Delete GetRandom O(1) - Duplicates allowed O(1) 时间插入、删除和获取随机元素 - 允许重复

    设计一个支持在平均 时间复杂度 O(1) 下, 执行以下操作的数据结构.注意: 允许出现重复元素.    insert(val):向集合中插入元素 val.    remove(val):当 val ...

  7. 283 Move Zeroes 移动零

    给定一个数组 nums, 编写一个函数将所有 0 移动到它的末尾,同时保持非零元素的相对顺序.例如, 定义 nums = [0, 1, 0, 3, 12],调用函数之后, nums 应为 [1, 3, ...

  8. [转]从数据到代码——基于T4的代码生成方式

    本文转自:http://www.cnblogs.com/artech/archive/2010/10/23/1859529.html 在之前写一篇文章<从数据到代码>(上篇.下篇)中,我通 ...

  9. redis+mysql读写方案

    前言:在web服务端开发的过程中,redis+mysql是最常用的存储解决方案,mysql存储着所有的业务数据,根据业务规模会采用相应的分库分表.读写分离.主备容灾.数据库集群等手段.但是由于mysq ...

  10. 北工大2017校赛 1101:要打车的FanZzz

    题目链接: http://bjutacm.openjudge.cn/lianxi/1101/ 思路: 二分 + 二分图最大匹配. 开始的时候我想直接用最小费用流模型,后来发现这样是错误的.因为这道题实 ...