以为是组合,后来看着像数位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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  5. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  6. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  7. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  8. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  9. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

随机推荐

  1. js实现的美女瀑布流效果代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  2. C实现头插法和尾插法来构建单链表(不带头结点)

    链表的构建事实上也就是不断插入节点的过程.而节点的插入能够分为头插法和尾插法. 头插法就是在头结点后插入该节点,始终把该节点作为第一个节点.尾插法就是在链表的最后一个节点处插入元素,作为最后一个节点. ...

  3. createElement与innerHtml性能比較

    js中.动态加入html的方法大致就是两种,一种是document.createElement等方法创建,然后使用Element.appendChild加入,或者是使用Element.innerHTM ...

  4. 关于Address already in use: connect问题分析及解决方案

    最近给一个公司做项目的时候,在完成上报的功能 的时候,发现数据量稍微大的时候,会出现这样的问题: 错误描述: com.microsoft.sqlserver.jdbc.SQLServerExcepti ...

  5. Repeater控件前台复杂逻辑判断

    虽然现在开发大都是前后台ajax的方式,但是还有部分项目用后台cs代码+服务器控件开发的方式,小弟今天就遇到了一个 repeater显示列表,有一个字段是state状态,数据库里面存的是0 1 2类似 ...

  6. centos7下比特币源码编译安装

    今天我们介绍比特币的源码安装过程,是利用编译安装的 首先安装依赖 1 yum install -y boost-devel qt-devel protobuf-devel qrencode-devel ...

  7. 如何在Android studio中同时打开多个工程?

    最近学习Android Studio,想同时打开两个Project.但是点击File->Open之后,原有的Project被关闭掉了.怎么在新的窗口中打开Project呢? 解决: 点击Help ...

  8. [HEOI 2012] 采花

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2743 [算法] 首先预处理nxt[]数组 , 其中 , nxt[i]表示下一个和i号 ...

  9. python-----从本地摄像头和网络摄像头截取图片

    import cv2 # 获取本地摄像头 # folder_path 截取图片的存储目录 def get_img_from_camera_local(folder_path): cap = cv2.V ...

  10. Python+页面元素高亮源码实例

    简单写了一个页面元素高亮的方法,原理就是在python中调用js实现元素高亮,分享一下源码如下: 1.元素高亮源码 Js调用 js = "var q=document.getElementB ...