链接:http://codeforces.com/contest/401/problem/D

题意:给出一个数字num和m,问通过重新排列num中的各位数字中有多少个数(mod m)=0,直接枚举全排列肯定不行,可以用状压dp来搞..

dp[S][k]表示选了num中的S且(mod m)=k的方案种数,初始条件dp[0][0]=1,转移方为dp[i|1<<j[(10*k+num[j])%m]+=dp[i}[k];,注意到是多重排列,所以还需要除去重复的。代码如

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn (1 << 18) + 5
#define LL long long
LL m,f[maxn][105];
char ch[20];
bool vis[20];
int main()
{
scanf("%s%lld", &ch, &m);
int n = strlen(ch);
f[0][0] = 1;
int e = (1 << n);
for(int i = 0 ; i < e ; i ++)
{
for(int j = 0 ; j < m ; j ++)
{
memset(vis, 0, sizeof vis);
for(int k = 0 ; k < n ; k ++)
{
int x = ch[k] - '0';
if(i & (1 << k)) continue;
if(i == 0 && x == 0) continue;
if(vis[x]) continue;
vis[x] = 1;
f[i|(1<<k)][(j*10+x)%m] += f[i][j];
}
}
}
cout<<f[e-1][0]<<endl;
return 0;
}

  

最新文章

  1. 跟我一起云计算(5)——Shards
  2. [解决方案]vs2015无法解析外部符号__imp__fprintf和__imp____iob_func
  3. T-SQL中的一些小陷阱
  4. Markdown的使用简介
  5. VS xsd Class
  6. Raw-OS源代码分析之消息系统-Queue_Size
  7. android 开源和一些博客总结
  8. 数据结构 -- 简单图的实现与遍历 (Java)
  9. BZOJ 3744 Gty的妹子序列
  10. on IRC, how to use secure connection(SSL) and get a cloak/vhost to hide your IP
  11. NSIndexSet 浅析
  12. linux 卸载安装node npm
  13. 20162302 实验四《Android程序设计》实验报告
  14. PHP 验证码 浅析
  15. /etc/profile文件被改坏导致命令不可用
  16. python通过手机抓取微信公众号
  17. LNOI2014LCA(树链剖分+离线操作+前缀和)
  18. ajax的原生调用
  19. python编译hello
  20. 响应式web设计之@media

热门文章

  1. ACM-ICPC 2018 I. Characters with Hash
  2. nyoj 170-网络的可靠性 (度为1)
  3. 【Java】面向对象之继承
  4. 构建 DNS 主从复制服务器
  5. 【SpringBoot | Swagger】SpringBoot整合Swagger
  6. Robot Framework自动化测试环境搭建
  7. uniapp打包Android APP
  8. 小程序取消IOS虚拟支付解决方案
  9. 【Luogu P1878】舞蹈课
  10. Pycharm报错连接linux服务器报错:Could not verify `ssh-rsa` host key with fingerprint