Beautiful Numbers
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的更多相关文章
- CodeForces 55D Beautiful numbers
		D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ... 
- [codeforces 55]D. Beautiful numbers
		[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ... 
- codeforces 55D - Beautiful numbers(数位DP+离散化)
		D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ... 
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
		C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ... 
- 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 ... 
- CF 55D - Beautiful numbers(数位DP)
		题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ... 
- Codeforces Beta Round #51 D. Beautiful numbers
		D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ... 
- Beautiful Numbers(牛客网)
		链接:https://ac.nowcoder.com/acm/problem/17385来源:牛客网 题目描述 NIBGNAUK is an odd boy and his taste is stra ... 
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
		传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ... 
- 【数位dp】Beautiful Numbers @2018acm上海大都会赛J
		目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ... 
随机推荐
- 让ie6/7/8兼容css3的圆角阴影等特殊效果的方法 PIE1.0.0及placeholder在这些IE下生效的方法
			PIE地址:http://css3pie.com/ 使用方法1: #login,#AnnouncementBox { border:3px solid #fff; -webkit-border-r ... 
- iis6 下发布MVC2项目的方法
			1.安装MVC2运行库,否则会出现错误 [以下转载]http://blog.csdn.net/xw13106209/article/details/6323695 错误:”未能加载文件或程序集“Sys ... 
- git代码库的使用
			代码库/使用指南 http://learn.zone.jd.com/cmsuser/index.htm 在win7系统下使用TortoiseGit(乌龟git)简单操作Git@OSC http://m ... 
- Oracle数据导入导出imp/exp命令总结
			racle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中. 利用 ... 
- iOS sizeWithFont 过期 is deprecated
			原文: http://www.cnblogs.com/A--G/p/4819189.html iOS 2.0之后 sizeWithFont就被弃用了: //计算textview 高度 - (float ... 
- 浮点数精确表示,java陷阱
			/** 浮点数表示问题 @author husky */ public class Change { public static void main(String[] args) { double n ... 
- html中的空格可以用什么代替
			半角空格用 代替,全角的空格可以直接在网页里生效. 打全角空格的两种方法:1.智能ABC按v1,选择第一个2.按shift+空格切换输入法的“半.全角”状态为全角再按空格 
- phpcms 标签解析
			phpcms 每个pc标签对应modules控制器下一个 tag.class类 比如 {pc:content action="position" posid="2&quo ... 
- 4种检测是否支持HTML5的方法,你知道几个?
			4种检测是否支持HTML5的方法,你知道几个? 1,检查特定的属性是否存在于全局的对象里面,比如说window或navigator. 比如geolocation,它是HTML5新加支持的新特性:它是由 ... 
- NLP相关资源
			一 NLP相关资源站点 Rouchester大学NLP/CL会议列表 一个非常好的会议时间信息网站,将自然语言处理和计算语言学领域的会议,按照时间月份顺序列出. NLPerJP 一个日本友好人士维护的 ... 
