CodeForces-Round235D
2024-10-11 19:18:55
链接: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;
}
最新文章
- 跟我一起云计算(5)——Shards
- [解决方案]vs2015无法解析外部符号__imp__fprintf和__imp____iob_func
- T-SQL中的一些小陷阱
- Markdown的使用简介
- VS xsd Class
- Raw-OS源代码分析之消息系统-Queue_Size
- android 开源和一些博客总结
- 数据结构 -- 简单图的实现与遍历 (Java)
- BZOJ 3744 Gty的妹子序列
- on IRC, how to use secure connection(SSL) and get a cloak/vhost to hide your IP
- NSIndexSet 浅析
- linux 卸载安装node npm
- 20162302 实验四《Android程序设计》实验报告
- PHP 验证码 浅析
- /etc/profile文件被改坏导致命令不可用
- python通过手机抓取微信公众号
- LNOI2014LCA(树链剖分+离线操作+前缀和)
- ajax的原生调用
- python编译hello
- 响应式web设计之@media
热门文章
- ACM-ICPC 2018 I. Characters with Hash
- nyoj 170-网络的可靠性 (度为1)
- 【Java】面向对象之继承
- 构建 DNS 主从复制服务器
- 【SpringBoot | Swagger】SpringBoot整合Swagger
- Robot Framework自动化测试环境搭建
- uniapp打包Android APP
- 小程序取消IOS虚拟支付解决方案
- 【Luogu P1878】舞蹈课
- Pycharm报错连接linux服务器报错:Could not verify `ssh-rsa` host key with fingerprint