Light oj 1021 - Painful Bases
题意: 给一个B进制的数,一个10进制的数K,B进制数有x位,
对着x位进行全排列的话,有x!种可能,
问这x!的可能中,有多少种可以整除K,各个位置上的数字都不同。
思路:状态压缩,数位DP
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#define MAXSIZE 70000
#define LL long long
using namespace std;
const long long INF = 1e18; //给一个B进制的数,一个10进制的数K,B进制数有x位,
//对着x位进行全排列的话,有x!种可能,
//问这x!的可能中,有多少种可以整除K,各个位置上的数字都不同。 LL dp[MAXSIZE][];
int b,k,bit[MAXSIZE],len;
char str[MAXSIZE];
LL dfs(int pos,int st,int mod)
{
if(pos < )
return mod == ;
if(dp[st][mod] != -)
return dp[st][mod];
LL ans = ;
for(int i=;i<len;i++)
{
if(st & (<<i))
continue;
else
{
ans += dfs(pos-,st|(<<i),((mod*b)+bit[i])%k);
}
} dp[st][mod] = ans;
return ans;
} LL Solve()
{
memset(dp,-,sizeof(dp)); len = strlen(str);
int pos = ;
for(int i=;i<len;i++)
{
if(str[i] >='' && str[i] <= '')
bit[pos++] = str[i] - '';
else
bit[pos++] = str[i] - 'A' + ;
} LL ans = dfs(pos-,,); return ans;
} int main()
{
int T,cns=;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&b,&k);
scanf("%s",str);
LL ans = Solve();
printf("Case %d: %lld\n",cns++,ans);
}
return ;
}
Light oj 1021 - Painful Bases的更多相关文章
- Light OJ 1021 - Painful Bases(状态压缩DP)
题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring ...
- 1021 - Painful Bases
1021 - Painful Bases PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB As ...
- lightoj 1021 - Painful Bases 状态压缩
题目链接:http://lightoj.com/volume_showproblem.php?problem=1021 #include<cstring> #include<cstd ...
- lightoj 1021 - Painful Bases(数位dp+状压)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1021 题解:简单的数位dp由于总共就只有16个存储一下状态就行了.求各种进制能 ...
- Painful Bases LightOJ - 1021
Painful Bases LightOJ - 1021 题意:给出0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F中的一些字符(不重复)还有一个进制base,求这些字符的排列形成的ba ...
- K - Painful Bases 状压dp
Painful Bases LightOJ - 1021 这个题目一开始看,感觉有点像数位dp,但是因为是最多有16进制,因为限制了每一个数字都不同最多就有16个数. 所以可以用状压dp,看网上题解是 ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
随机推荐
- TODO java疑问
TODOjava 疑惑-关于方法调用的参数是基本类型和引用类型的差别 class DataWrap { int a; int b; } public class ReferenceTransferTe ...
- POJ 3522 Slim Span(极差最小生成树)
Slim Span Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 9546 Accepted: 5076 Descrip ...
- (线性dp,LCS) POJ 1458 Common Subsequence
Common Subsequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 65333 Accepted: 27 ...
- php中函数里面使用函数外面的变量
一定要在函数里面声明为全局变量!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(不然会有问题,还是不报错的那种)
- Grunt安装与环境配置
公司项目还没有前后端分离,而前端是使用node.js搭建起来的,现在需要自己动手开发,故学习下并做为记录防止以后忘记. grunt依赖node.js,所以在安装之前确保你安装了 Node.js.然后开 ...
- nginx配置模板问题404
nginx配置模板问题 一.nginx主配置文件如下 cat /etc/nginx/nginx.conf user nginx; worker_processes ; #error_log logs/ ...
- hostnamectl 修改 CentOS7 主机名
hostnamectl 控制主机名 # 显示状态 hostnamectl Static hostname: centos Icon name: computer-vm Chassis: vm Mach ...
- python Bootstarp框架和inconfont、font-awesome使用
http://www.bootcss.com/ http://www.runoob.com/bootstrap/bootstrap-panels.html 查找基本的没问题 https://www. ...
- python 面向对象(三)类与类之间的关系 初始化方法一些类
###################总结################# 面试的时候 让写python一些特殊方法 __init__ 创建对象的时候初始化 __new__对象实例化调用第一个方法 ...
- Hadoop记录-Hadoop NameNode 高可用 (High Availability) 实现解析
Hadoop NameNode 高可用 (High Availability) 实现解析 NameNode 高可用整体架构概述 在 Hadoop 1.0 时代,Hadoop 的两大核心组件 HDF ...