http://codeforces.com/problemset/problem/300/C

题意:给你三个数a,b,n;求满足由a,b组成的n位的个数,且每个位置上的数之和也是用a,b组成;

解析:由题意设a的个数为x,b的个数为y,那么x+y==n;因此枚举满足条件的x的值,然后对这x个a和y进行排列组合。

满足条件的个数为n!/(x!*y!);直接求解会超时。

因此,对该等式进行求逆元,A×inv( b ) % Mod;inv( b ) = pow( b , Mod - 2 );

带入求解。

// File Name: c.cpp
// Author: bo_jwolf
// Created Time: 2013年10月08日 星期二 15:11:26 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> using namespace std;
const int maxn = 1000005;
long long num[ maxn ];
#define Mod 1000000007 bool judge( long long n, int x, int y ){
while( n ){
int temp = n % 10;
if( temp != x && temp != y )
return 0;
n /= 10;
}
return 1;
} long long Pow_mod( long long a, long long b ){
long long ans = 1;
while( b ){
if( b & 1 ){
ans = ( ans * a ) % Mod;
b--;
}
a = ( a * a ) % Mod;
b >>= 1;
}
return ans;
} int main(){
num[ 0 ] = 1;
for( int i = 1; i < maxn; ++i )
num[ i ] = ( num[ i - 1 ] * i ) % Mod;
int a, b, n;
long long ans;
while( scanf( "%d%d%d", &a, &b, &n ) != EOF ){
ans = 0;
for( int i = 0; i <= n; ++i ){
int j = n - i;
if( judge( ( i * a + j * b ), a, b ) ){
ans += ( num[ n ] * Pow_mod( num[ i ], Mod - 2 ) )% Mod * ( Pow_mod( num[ n - i ], Mod - 2 ) ) % Mod ;
ans %= Mod;
}
}
printf( "%lld\n", ans );
}
return 0;
}

Beautiful Numbers的更多相关文章

  1. CodeForces 55D Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. [codeforces 55]D. Beautiful numbers

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

  3. codeforces 55D - Beautiful numbers(数位DP+离散化)

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

  5. Codeforces Beta Round #51 D. Beautiful numbers 数位dp

    D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...

  6. CF 55D - Beautiful numbers(数位DP)

    题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...

  7. Codeforces Beta Round #51 D. Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  8. Beautiful Numbers(牛客网)

    链接:https://ac.nowcoder.com/acm/problem/17385来源:牛客网 题目描述 NIBGNAUK is an odd boy and his taste is stra ...

  9. CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)

    传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...

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

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

随机推荐

  1. ashx页面 “检测到有潜在危险的 Request.Form 值”的解决方法(控制单个处理程序不检测html标签)

    如题: 使用web.config的configuration/location节点. 在configuration节点内新建一个location节点,注意这个节点和system.webserver那些 ...

  2. CSS3美化表单控件

    表单的默认控件在不同的浏览器中的样式不同,用户体验很差.用CSS3可以实现表单控件的美化,可以提供更好的用户体验.不足之处就是浏览器的兼容性问题. 一.下拉控件 效果图: 下拉控件的布局结构: < ...

  3. Spring 中的注解

    1.普通方式注解 a.在配置文件中配置 1.导入命名空间              xmlns:context="http://www.springframework.org/schema/ ...

  4. Vijos P1521 跳舞 贪心

    本来想找一道网络流的题来着,结果这道题越看越不对劲,总觉得这题存在不用网络流的解法 看了题解区以后坚定了自己的猜想 #include <cstdio> #include <cstri ...

  5. 线程取消 (pthread_cancel)

    线程取消(pthread_cancel) 基本概念pthread_cancel调用并不等待线程终止,它只提出请求.线程在取消请求(pthread_cancel)发出后会继续运行,直到到达某个取消点(C ...

  6. SGU 163.Wise King

    一道题目长的水题.... 总结就一句话,给出n个(-3~3)的数,一个数m,取任意个数是使这些数的m次幂之和最大. code #include <iostream> #include &l ...

  7. 关于jQuery的cookies插件2.2.0版设置过期时间的说明

    欢迎转载,转载请注明作者RunningOn jQuery应该是各位用JavaScript做web开发的常用工具了,它有些插件能非常方便地操作cookie. 不过非常让人郁闷的是,网上几乎所有人对于这些 ...

  8. Python入门,新手之路

    1.开始使用Python: 从上一篇中我们提到了第一个Python,print("Hello World!")程序说起,看到这一句话,你有没有想过如果括号中的语句不是Hello W ...

  9. WinPcap编程(一)

    0. 按着文档顺序写的. 开发环境:win10+VS2013. 配置WinPcap环境就不多说.直接给网址:http://blog.sina.com.cn/s/blog_57432f380101qh3 ...

  10. 简单的贴图显示shander

    Shader "ztq/Diffuse" {    Properties {           _Color ("Main Color", Color) =  ...