Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
2013-10-11 17:55
337 查看
B. Little Elephant and Elections
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other
parties have less catchy names.
Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m.
Each of these 7parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.
The Little Elephant Political Party members believe in the lucky digits 4 and 7.
They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number
of lucky digits in the ballot numbers of 6 other parties.
Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by1000000007 (109 + 7).
Input
A single line contains a single positive integer m (7 ≤ m ≤ 109) —
the number of possible numbers in the ballot.
Output
In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Sample test(s)
input
output
input
output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other
parties have less catchy names.
Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m.
Each of these 7parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.
The Little Elephant Political Party members believe in the lucky digits 4 and 7.
They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number
of lucky digits in the ballot numbers of 6 other parties.
Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by1000000007 (109 + 7).
Input
A single line contains a single positive integer m (7 ≤ m ≤ 109) —
the number of possible numbers in the ballot.
Output
In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Sample test(s)
input
7
output
0
input
8
output
1440
数位dp,可以,先把所有有i个4,7的个数的数的个数用数位dp,求出来,然后,就是这10之间的组合数了!用一个简单搜索就可以了!
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdio.h>
#define MOD 1000000007using namespace std;
__int64 c[11][11],dp[11],ans;
int pri[30];
void dfs(int pos,int x,__int64 s){
if(pos>5){ans=(ans+s)%MOD;return ;}
for(int i=0;i<x;i++)
if(dp[i])
dp[i]--,dfs(pos+1,x-i,(dp[i]+1)*s%MOD),dp[i]++;
}
int main (){
int m,i,j,k;
for(i=0;i<11;i++)
for(j=0;j<=i;j++)
c[i][j]=i&&j?c[i-1][j-1]+c[i-1][j]:1;
while(scanf("%d",&m)!=EOF){
int n=0,cnt=0;
__int64 len;m++;
memset(dp,0,sizeof(dp));dp[0]--;
while(m){pri[++n]=m%10;m/=10;}
for(i=n;i>0;i--){
for(j=0;j<pri[i];j++){
len=(__int64)1<<(i-1);
for(k=i-1;k>=0;k--){
dp[cnt+k+(j==4||j==7)]=(dp[cnt+k+(j==4||j==7)]+c[i-1][k]*len)%MOD;
len<<=2;
}
}
cnt+=pri[i]==4||pri[i]==7;
}
for(ans=0,i=0;i<10;i++){
if(dp[i])dp[i]--,dfs(0,i,dp[i]+1),dp[i]++;
}
cout<<ans<<endl;
}
return 0;
}
相关文章推荐
- Windows phone 8 推送
- POJ 3732 —— kruskal
- Nginx 安装
- hive介绍
- extjs表格文本启用选择复制功能具体实现
- POJ 1265 Area Pick定理
- 如何注册.net 的类库dll 为com组件
- DB2 9.5 数据库分区管理及应用实践
- 安卓 9.png 图片的制作
- 端口映射
- NDK Plugin下载
- 4 互斥锁的弱化版本:读写锁
- 谈谈C++中的const
- Java的反射机制
- String、StringBuffer与StringBuilder之间区别
- 嵌入式环境图形加速浅析(以机顶盒平台为例)
- 几种网络负载均衡方法比较
- android service (官方文档翻译)
- 循环赛程安排
- Asp.net页面生命周期详解任我行(3)-服务器处理请求详细过程