CF 258B Little Elephant and Elections
来源:互联网 发布:淘宝手机店铺打不开 编辑:程序博客网 时间:2024/05/23 01:12
数位dp。 先找出含不同数目幸运数字的数量。然后直接暴力求解。
本题是第一次做这种找不同数目特定数字的数位dp,加一个参量。在函数外面加一重循环,指定数目,最后判断是否与预期数目相同即可。
暴力求种类数每一个政党可能选的所有数目是相加的,每一种数目的下的种类与后面政党的所有可能数相乘。一开始全部相乘搞错了。波神是dp过的,10^5,优化了两个数量级。感觉没有太大必要
提交时db了两次,第一是交错题,然后INF是1000000007,我令为1000000009了。。。
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;#define INF 1000000007#define LL long longchar a[20];LL sum[20];LL dp[20][20];int len;LL dfs(int id, int s, bool d, int aim){ if(s > aim) return 0; if(id >= len) return s == aim; if(dp[id][s] != -1 && !d)return dp[id][s]; int edge = d ? a[id] - '0' : 9; LL ans = 0; for(int i = 0; i <= edge; i++){ if(i == 4 || i == 7) ans += dfs(id + 1, s + 1, d && i == edge, aim); else ans += dfs(id + 1, s , d && i == edge, aim); } return d ? ans : dp[id][s] = ans;}LL dfs2(int id, int num, int sn){ if(id >= 6)return num < sn ? 1 : 0; LL ans = 0; for(int i = 0; i < sn - num; i++){ if(sum[i] > 0){ sum[i] --; ans += (sum[i] + 1) * dfs2(id + 1, num + i, sn) % INF; ans %= INF; sum[i] ++; } } return ans;}int main(){ scanf("%s", a); len = strlen(a); memset(sum, 0, sizeof(sum)); for(int i = 0; i <= 9; i++){ memset(dp, -1, sizeof(dp)); sum[i] = dfs(0, 0, true, i); if(i == 0)sum[0]--; }//printf("\n"); LL ans = 0; for(int i = 0; i <= 9; i++){ if(sum[i] > 0){ ans += sum[i] * dfs2(0, 0, i) % INF; ans %= INF; } } printf("%I64d\n", ans); return 0;}
0 0
- CF 258B Little Elephant and Elections
- CF 258B Little Elephant and Elections [dp+组合]
- Codeforces-258B Little Elephant and Elections
- Codeforces 258B Little Elephant and Elections
- Codeforces 258B - Little Elephant and Elections
- 数位dp + dfs + 逆元求余 CF 258 B. Little Elephant and Elections
- 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】
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- CF 220B Little Elephant and Array
- CF 205B Little Elephant and Sorting
- [Codeforces 258B & 259 D]Little Elephant and Elections 数位dp+dfs
- CF Little Elephant and Shifts
- Codeforces Round #157 (Div. 1)B. Little Elephant and Elections 数位dp好
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp
- hdu——1050——Moving Tables
- 计算机基本编码 UTF-8 与 UTF-16 的优劣
- PHP编码规范(1)
- 学习与生活
- 程序员的奋斗史(三十四)——人在囧途之应聘篇(四)
- CF 258B Little Elephant and Elections
- java命名规则和数据类型
- struts2的上传
- 豆瓣robots.txt分析
- 索引的基本概念、分类、优点、使用
- 九度oj 题目1014:排名 【ZJU2005机试题5】
- win7中VC6.0 visual C++6.0无法打开文件和向工程中添加文件的解决办法【已添加部分注释】
- 内存数据库fastdb
- 洗牌算法-神级算法来源