lightoj 1021 (数位DP)
题意:给你一个b进制的数,再给你一个十进制数k,你可以重新排列b进制数的每一位得到其他b进制数,问你这些数中有多少可以整除k?
思路:数位dp。
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long int dp[1 << 16][20];
int hashDigit(char ch){
if(ch >= '0' && ch <= '9') return ch-'0';
return 10 + ch - 'A';
}
int main(){
int t,b,K,CASE(0);
char str[20];
scanf("%d",&t);
while(t--){
scanf("%d%d%s",&b,&K,str);
memset(dp,0,sizeof dp);
dp[0][0] = 1;
int len = strlen(str),range = 1 << len;
for(int i = 0;i < range;i ++){
for(int j = 0;j < len;j ++){
if(i & (1 << j)) continue;
for(int k = 0;k < K;k ++)
dp[i|(1 << j)][(k*b + hashDigit(str[j]))%K] += dp[i][k];
}
}
printf("Case %d: %lld\n",++CASE,dp[range-1][0]);
}
return 0;
}
lightoj 1021 (数位DP)的更多相关文章
- LightOJ - 1032 数位DP
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...
- Lightoj 1068(数位DP)
求一段区间中被k整除,各个位数相加之和被k整除的数的个数. 这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组. 仔细分析一下可以发现,由于数最大是2的31次方(2147483 ...
- Lightoj 1140(数位DP)
求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就 ...
- lightoj 1205 数位dp
1205 - Palindromic Numbers PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- lightoj 1021 - Painful Bases(数位dp+状压)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1021 题解:简单的数位dp由于总共就只有16个存储一下状态就行了.求各种进制能 ...
- LightOJ 1032 - Fast Bit Calculations 数位DP
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表 ...
- LightOJ 1068 Investigation (数位dp)
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...
- 数位dp(D - How Many Zeroes? LightOJ - 1140 )
题目链接:https://cn.vjudge.net/contest/278036#problem/D 题目大意:T组测试数据,每一次输入两个数,求的是在这个区间里面,有多少个0,比如说19203包括 ...
- LightOJ 1140 计数/数位DP 入门
题意: 给出a,b求区间a,b内写下过多少个零 题解:计数问题一般都会牵扯到数位DP,DP我写的少,这道当作入门了,DFS写法有固定的模板可套用 dp[p][count] 代表在p位 且前面出现过co ...
随机推荐
- BZOJ 3129 SDOI2013 方程
如果没有限制,答案直接用隔板法C(m-1,n-1) 对于>=x的限制,我们直接在对应位置先放上x-1即可,即m=m-(x-1) 对于<=x的限制,由于限制很小我们可以利用容斥原理将它转化为 ...
- hdu 1978 How many ways
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...
- nodejs搭配phantomjs highcharts后台生成图表
简单分享一下,后台使用nodejs结合highcharts.phantomjs生成报表图片的方法.这主要应用在日报邮件. 主要参考以下资料: http://www.highcharts.com/com ...
- Failed to allocate memory: 8
Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...
- 语言基础:C#输入输出与数据类型及其转换
今天学习了C#的定义及特点,Visual Studio.Net的集成开发环境和C#语言基础. C#语言基础资料——输入输出与数据类型及其转换 函数的四要素:名称,输入,输出,加工 输出 Console ...
- maven小项目注册服务(三)--web模块
java的web应用打包方式一般为war它和jar的区别就是包含了更多的资源和文件,如JSP文件,静态资源文件,servlet等等.war包的核心就WEB-INF文件夹下必须有一个web.xml 的配 ...
- Android开发之LocationManager和定位
代码: /* * 获取当前的位置,并通过短信发送位置到指定号码 */ public class LocationService extends Service { private LocationMa ...
- git push提示或错误
当 git 和 gerrit 一起使用的时候,你创建了一个 tag,现在需要 push 到远程仓库,当你没有权限的时候,会出现如下提示: $ git push origin v20150203 Tot ...
- Codeforces 4538 (状态压缩dp)Little Pony and Harmony Chest
Little Pony and Harmony Chest 经典状态压缩dp #include <cstdio> #include <cstring> #include < ...
- bzoj1876: [SDOI2009]SuperGCD
更相减损数. 上手就debug了3个小时,直接给我看哭了. 3个函数都写错了是什么感受? 乘2函数要从前往后乘,这样后面的数乘2进位以后不会干扰前面的数. 除2函数要从后往前除,这样前面的数借来的位不 ...