Beautiful Numbers
来源:互联网 发布:java 客户端ip 编辑:程序博客网 时间:2024/05/16 12:39
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 1000000007bool 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
- Beautiful numbers
- Beautiful Numbers
- Beautiful numbers
- Beautiful numbers
- Why are numbers beautiful?
- Codeforces_C - Beautiful Numbers
- codeforces Beautiful Numbers
- UVa 11472 - Beautiful Numbers
- codeforces55D Beautiful numbers
- codeforces300C. Beautiful Numbers
- C. Beautiful Numbers
- E - Beautiful Numbers
- 数位dp Beautiful numbers
- 数位dp, Beautiful numbers
- Beautiful numbers CodeForces
- Beautiful numbers CodeForces
- HOJ-1983-Beautiful numbers
- 二叉树的遍历Java实现_world
- JNI入门
- linux硬链接与软链接
- 【§失控的可怕(oo)壁纸】
- C++重载输入和输出操作符以及IO标准库中的刷新输入缓冲区残留字符问题
- Beautiful Numbers
- 根据要素选择集,创建新图层
- 如何查看本地电脑上端口号的使用情况
- WebService 的创建,部署和使用
- FL2400--YAFFS2文件系统移植(三)
- 一个程序员最终归宿
- mahout的数据处理--【根据文本文件创建vector】
- OCP-1Z0-053-V12.02-380题
- 理解链路本地址与站点本地地址