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

【题意】

让你找到长度为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. Permutations II 典型去重

    https://leetcode.com/problems/permutations-ii/ Given a collection of numbers that might contain dupl ...

  2. hdu4292 Food 最大流模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4292 题意:水和饮料,建图跑最大流模板. 我用的是学长的模板,最然我还没有仔细理解,不过这都不重要直接 ...

  3. E20180127-hm

    retain  vt. 保持; 留在心中,记住; 雇用; 付定金保留;

  4. bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】

    最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...

  5. SQL 经典语句大全

    原地址:http://www.cnblogs.com/yubinfeng/archive/2010/11/02/1867386.html 一.基础 1.说明:创建数据库 CREATE DATABASE ...

  6. DHTML_____window对象的事件

    <html> <head> <meta charset="utf-8"> <title>window对象事件</title&g ...

  7. new mysqli_ and 旧mysql

    旧的php处理语法: 1. <select name="s" onChange="redirec()"> <option selected&g ...

  8. mysql-installer-web-community-5.7.18.1.msi的安装(图文详解)

    不多说,直接上干货! 说在前面的话 我为什么已经尝试和使用过同类型产品的很多MySQL版本,还要书写这篇博客呢?基于mysql-installer-web-community-5.7.18.1.msi ...

  9. 初识mybatis之入门案例

    我也是自学了一下,在idea中基于maven的mybatis的配置.有什么不对的地方,请指正,谢谢. 1.1咋们先来配置测试一下,配置mybatis的图解: 1.2 pom.xml需要mybatis的 ...

  10. datagrid上面的查询按钮设置了,但是分页工具栏不显示

    原因:查询的linkbutton没有放在toolbar里. <script type="text/javascript"> $(function(){ $('#dg') ...