CF258B
CF258B
题意:
7个人在 $ [1,m] $ 区间内取数,求第一个人选的数的4和7的个数大于其他人的4和7个数总和的方案数。
解法:
要求输入的 $ m $ 可以很大,而且需要按位考虑每隔人的贡献,所以考虑数位DP。
设 $ f[i][j] $ 表示到第 $ i $ 位,有 $ j $ 个数是 $ 4 和 7 $ 的方案数,再利用dfs进行转移就行。
CODE :
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
const LL MOD = 1e9+7;
LL final,dp[16][16],c[16];
int bit[16],l,cnt,tot,m;
int work(int m, int n) {
cnt = tot = l = 0;
for (; m; m /= 10) bit[++l] = m % 10;
for (int i = l; i && tot <= n; --i) {
for(int j = 0 ; j < bit[i] ; j++)
if (j == 4 || j == 7) {
if (tot < n) cnt += dp[i - 1][n - tot - 1];
} else cnt += dp[i - 1][n - tot];
if (bit[i] == 4 || bit[i] == 7) ++tot;
}
if(tot == n) ++cnt;
if(n == 0) --cnt;
return cnt;
}
void dfs(int t, int now, int lim, LL ans) {
if (t == 6) (final += ans) %= MOD;
else {
for (int i = 0; i <= 9 && i + now < lim; ++i)
if (c[i]) {
c[i]--;
dfs(t + 1, now + i, lim, ans * (c[i] + 1) % MOD);
c[i]++;
}
}
}
int main() {
scanf("%d", &m);
dp[0][0] = 1;
for(int i = 0 ; i <= 9 ; i++) {
for(int j = 0 ; j <= i ; j++) {
dp[i + 1][j + 1] += dp[i][j] * 2;
dp[i + 1][j] += dp[i][j] * 8;
}
}
for(int i = 0 ; i <= 9 ; i++) c[i] = work(m, i);
for(int i = 0 ; i <= 9 ; i++) {
if (c[i]) {
--c[i];
dfs(0, 0, i, (c[i] + 1) % MOD);
++c[i];
}
}
printf("%lld \n", final);
//system("pause");
return 0;
}
CF258B的更多相关文章
随机推荐
- 怎样修改 VS Code 主题?
方法1. 点击左上角 File > Preferences > Color Theme. 方法2. 使用快捷键: Ctrl + K , Ctrl + T PS: 查询各种操作的快捷键可以 ...
- centos中拉取postgre
新搭建好的linux服务器环境,docker也配置好了. 第一步,下载postgre docker pull postgres:11 这里的版本号自己按照自己的需要来获取. 然而实际上没那么顺利,直接 ...
- IExtenderProvider,c#组件扩展控件属性
[ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...
- MyEclipse优化攻略搜集
1 首先内存设置 不会报讨厌的内存溢出out of memory 和 henp space 在 myeclipse.ini把大小调成一样是因为不让myeclipse频繁的换内存区域的大小. #utf8 ...
- C++ 构造函数后面的冒号的作用
其实冒号后的内容是初始化成员列表,一般有三种情况: 1.对含有对象成员的对象进行初始化,例如, 类line有两个私有对象成员startpoint.endpoint,line的构造函数写 ...
- element-ui 中 el-table 相关操作
1.带checkbox 获取所有选择的行. this.$refs.multipleTable.selection 获取选中的单行 this.$refs.roleTable.store.states. ...
- 【Distributed】大型网站高并发和高可用
一.DNS域名解析 二.大型网站系统应有的特点 三.网站架构演变过程 3.1 传统架构 3.2 分布式架构 3.3 SOA架构 3.4 微服务架构 四.高并发设计原则 4.1 拆分系统 4.2 服务化 ...
- 调查问卷WebApp
1. 效果演示 2. 主要知识点 使用slot分发内容 动态组件 组件通信 实例的生命周期 表单 3. 遇到的问题 bus 通信 第一次 $on 监听不到 // 解决bus 第一次通信 $on 监听不 ...
- 用例图,ER图,架构图
用例图 ER图 架构图 注:附上小组画图文档链接 提取码:t7ij v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VM ...
- (备忘)Nodepad++常用快捷键
Ctrl-H 打开Find / Replace 对话框 Ctrl-D 复制当前行 Ctrl-L 删除当前行 Ctrl-T 上下行交换 F3 找下一个 Shift-F3 找上一个 Ctrl-Shift- ...