Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
来源:互联网 发布:女生用的吉他淘宝 编辑:程序博客网 时间:2024/05/29 04:34
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).
A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.
In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
7
0
8
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;}
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- Codeforces Round #157 (Div. 1)B. Little Elephant and Elections 数位dp好
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp
- Codeforces-258B Little Elephant and Elections
- Codeforces 258B Little Elephant and Elections
- Codeforces 258B - Little Elephant and Elections
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #129 (Div. 1) B. Little Elephant and Cards
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #136 (Div. 1) B. Little Elephant and Array
- Codeforces Round #157 (Div. 1)---A. Little Elephant and Bits
- Codeforces Round #129 (Div. 2) B. Little Elephant and Sorting
- Codeforces Round #136 (Div. 2) B. Little Elephant and Numbers
- codeforces 258B Little Elephant and Elections 数位DP+DFS
- CodeForces 258B Little Elephant and Elections 数位DP
- codeforces 258B - Little Elephant and Elections 数位DP
- codeforces 258B Little Elephant and Elections 数位DP+排列组合
- Codeforces 258B. Little Elephant and Elections【数位DP,DFS】
- Python3.3.0+apache2.4.4+django1.5.4+mod_wsgi3.4安装
- 几种网络负载均衡方法比较
- MySQL查询语句执行过程及性能优化-基本概念和EXPLAIN语句简介
- 4 互斥锁的弱化版本:读写锁
- POJ 1265 Area Pick定理
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- log4cplus 学习笔记
- Rhel上安装oracle的配置参数解析,pam,limits,profile
- hive介绍
- 拷贝构造函数与赋值构造函数(operator=)的区别
- Android APK反编译详解(附图)
- hive的数据类型和数据模型
- 【Nginx】基本配置入门
- [ORACLE]UTL_SMTP发邮件