Codeforces Round #235 (Div. 2) D (dp)
以为是组合,后来看着像数位dp,又不知道怎么让它不重复用。。然后就没思路 了。
其实状压就可以了 状压是可以确定一个数的使用顺序的 利用01也可以确定所有的数的使用以及不重复
dp[i+1《《e][(j*10+p[e])%m]+=dp[i][j]; 排下序去掉重复的 或者最后除去每个数出现的次数
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[<<][];
int o[];
int main()
{
LL n;
int m,i,j,a;
while(cin>>n>>m)
{
memset(dp,,sizeof(dp));
LL x = n;
int g = ;
while(x)
{
o[g++] = x%;
x/=;
}
sort(o,o+g);
int pp= - ;
for(i = ; i < g ;i++)
if(o[i]!=pp&&o[i]!=)
{
dp[<<i][o[i]%m] = ;
pp = o[i];
}
//dp[0][0] = 1;
//for(a = 2; a <= g ; a++)
//{
for(i = ;i < (<<g) ; i++)
{
for(j = ; j < m ;j++)
{
if(dp[i][j])
{
int pre = -;
for(int e = ; e < g ;e++)
{
if(o[e]==pre) continue;
if(i&(<<e)) continue;
if(i==&&o[e]==) continue;
dp[i+(<<e)][(j*+o[e])%m]+=dp[i][j];
pre = o[e];
} }
}
}
// }
cout<<dp[(<<g)-][]<<endl;
}
return ;
}
Codeforces Round #235 (Div. 2) D (dp)的更多相关文章
- Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)
Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp
题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
随机推荐
- 【SICP练习】149 练习4.5
练习4-5 原文 Exercise 4.5. Scheme allows an additional syntax for cond clauses, ( => ). If evaluates ...
- cmd下复制粘贴
cmd下复制粘贴的快捷操作方式 工具/原料 系统cmd 步骤/方法 1 如右图,右键命令提示符窗口的标题栏,选择属性. 2 选择“编辑选项”里的“快速编辑模式”,并确定之: 3 在弹出的应用选择提示框 ...
- 【iOS系列】-使用CAGradientLayer设置渐变色
有时候iOS开发中需要使用到渐变色,来给图片或者view盖上一层,使其显示效果更好,我们这里使用的CAGradientLayer来设置渐变色 要实现的效果如下: Demo地址---下载 // 创建渐变 ...
- JS Debug
任何一个编程者都少不了要去调试代码,不管你是高手还是菜鸟,调试程序都是一项必不可少的工作.一般来说调试程序是在编写代码之后或测试期修改Bug 时进行的,往往在调试代码期间更加能够体现出编程者的水平高低 ...
- cocos2d-x 打包成so文件之后,假设出现错误,能够使用ndk-stack来查看里面的异常
cocos2d-x 打包成so文件之后,假设出现错误,能够使用ndk-stack来查看里面的异常 详细方法.自行百度.
- Deep Learning 28:读论文“Multi Column Deep Neural Network for Traffic Sign Classification”-------MCDNN 简单理解
读这篇论文“ Multi Column Deep Neural Network for Traffic Sign Classification”是为了更加理解,论文“Multi-column Deep ...
- gsm model二次开发C#短信猫开发/长短信
加QQ:83014588 向我索要,开发包 开发人员淘宝:http://t.cn/RhOj8W8 短信猫:http://item.taobao.com/item.htm?spm=686.1000925 ...
- HDU1260 Tickets —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1260 Tickets Time Limit: 2000/1000 MS (Java/Oth ...
- svn回到历史的某个版本
svn回到历史的某个版本 分类: linux大类2011-08-05 10:25 7468人阅读 评论(0) 收藏 举报 svntortoisesvn svn回到历史的某个版本在代码的编写过程中,难免 ...
- 同步 Github fork 分支
/**************************************************************************** * 同步 Github fork 分支 * ...