codeforces 401D (数位DP)
思路:很明显的数位dp,设dp[i][j] 表示选取数字的状态为i,模m等于j的数的个数,那么最后的答案就是dp[(1<<n)-1][0]。状态转移方程就是,dp[i|(1<<k)][(10*j+n[j])%m]+=dp[i][k]
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
const int MAXN = 18;
const int MAXM = 101;
LL dp[1 << MAXN][MAXM], d = 1;
int main(){
int l, m, len, c[10] = {0};
char n[20];
cin >> n >> m;
l = strlen(n), len = (1 << l);
dp[0][0] = 1;
for(int i = 0;i < l;i ++) d *= ++c[n[i] -= '0'];
for(int i = 0;i < len;i ++){
for(int j = 0;j < l;j ++){
if(i & (1 << j)) continue;
if(i || n[j]){
for(int k = 0;k < m;k ++)
dp[i|(1<<j)][(k*10+n[j])%m] += dp[i][k];
}
}
}
cout << dp[len-1][0]/d << endl;
}
codeforces 401D (数位DP)的更多相关文章
- Codeforces 55D (数位DP+离散化+数论)
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...
- Codeforces 628D 数位dp
题意:d magic number(0<=d<9)的意思就是一个数,从最高位开始奇数位不是d,偶数位是d 题目问,给a,b,m,d(a<=b,m<2000)问,a,b之间有多少 ...
- Travelling Salesman and Special Numbers CodeForces - 914C (数位dp)
大意: 对于一个数$x$, 每次操作可将$x$变为$x$二进制中1的个数 定义经过k次操作变为1的数为好数, 求$[1,n]$中有多少个好数 注意到n二进制位最大1000位, 经过一次操作后一定变为1 ...
- Codeforces - 914C 数位DP
题意有点难以描述,简略的就是给定一个二进制\(n\),每一步操作能使\(n\)的位为1的数的和转化为一个十进制,然后转化为该数的二进制再进行相同的操作 查询\([0,n]\)中操作数恰好为\(k\)的 ...
- codeforces 55D 数位dp
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Shovel Sale CodeForces - 899D (数位dp)
大意: n把铲子, 价格1,2,3,...n, 求有多少个二元组(x,y), 满足x+y末尾数字9的个数最多. 枚举最高位, 转化为从[1,n]中选出多少个二元组和为$x$, 枚举较小的数 若$n\g ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Gym 100231L Intervals 数位DP
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...
随机推荐
- 构建第一个Java程序
- 读书笔记 (一) ———Fundamentals of Multiagent Systems with NetLogo Examples by Prof. Jose M Vidal
在网上发现Prof. Jose M Vidal用NetLogo仿真Multi-agent system的视频,随后下载他的著作Fundamentals of Multiagent Systems wi ...
- linux 下安装JDK1.7
安装JDK1.7 1. 打开网址http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u5-downloads-1591156.ht ...
- Extjs4.2布局——Ext.container.ViewportView
先贴出官方文档的关于此布局的描述:“ 一个专门的容器用于可视应用领域(浏览器窗口). Viewport渲染自身到网页的documet body区域, 并自动将自己调整到适合浏览器窗口的大小,在窗口大小 ...
- ExtJS4.2学习(六)表格分页与通过后台脚本获得分页数据
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-12/175.html --------------- ...
- JS中如何定义全局变量
三种方法 1.在js的function外定义一个变量 var name='测试'; function XX(){ alert(name); } 2.不使用var,直接给定义变量,隐式的声 ...
- 安装ADT Cannot complete the install because one or more required items could not be found.
点击进行安装,将会弹出 错误提示是: Cannot complete the install because one or more required items could not be found ...
- 用 OneAPM Cloud Insight 监控 Docker 性能
Docker 是构建和部署软件的一个新兴的轻量级的平台,也是一个减轻替代虚拟机的容器.Docker 通过给开发者提供兼容不同环境的镜像,成为解决现代基础设施的持续交付的一个流行的解决方案. 和虚拟机一 ...
- CF 369 B. Valera and Contest
http://codeforces.com/contest/369/problem/B 题意 :n, k, l, r, sall, sk,n代表的是n个人,这n个人的总分是sall,每个人的得分大于 ...
- Android 图片旋转(使用Matrix.setRotate方法)
imageView2 = (ImageView) findViewById(R.id.img2); Bitmap bitmap = BitmapFactory.decodeResource(getRe ...