Lightoj 1068(数位DP)】的更多相关文章

求一段区间中被k整除,各个位数相加之和被k整除的数的个数. 这不是重点,重点是k太大了,最大值有10000,所以不能直接开那么大的数组. 仔细分析一下可以发现,由于数最大是2的31次方(2147483648),所以当k>90时,直接输出0即可. #include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; #def…
题意:给你一个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]…
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #include<bitset>…
求一个区间内的数含有多少个0. dp[len][pre]表示长度为len的数,含有pre个0. 需要加一个标记,来表示前缀是否为0(可以是一串连续的0),如果前缀一直为0,就一直搜,如果前缀不为0,就可以用到dp[len-1][pre+1]或者dp[len-1][pre] 了,如果前缀的最后一位是0,就是dp[len-1][pre+1],如果前缀的最后一位不是0,就是dp[len-1][pre],当然了第一次肯定是需要先搜的. #include <iostream> #include <…
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <iostream> #include <algorithm> #include <climits> #include <queue> #define ll long long using namespace std; ; ],l,k; ll…
1205 - Palindromic Numbers    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this probl…
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数字之和也能被K整除的数的个数.(1 ≤ A ≤ B < 231 and 0 < K < 10000) 算是最简单的数位dp了.k在这里是10000.三维数组都开不开.可是想想会发现A,B最多有10位,各位数字之和不会超过90.那么当 k >= 90时,就不用dp,由于个位数字之和对k取…
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表第i位为j,前面已有k个1的个数. /** @Date : 2016-12-17-13.51 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : */ #include<bits/…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1021 题解:简单的数位dp由于总共就只有16个存储一下状态就行了.求各种进制能否整除k模仿10进制就行. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; typedef long long ll;…
思路:典型的数位DP!!! dp[i][j][k]:第i位,对mod取余为j,数字和对mod取余为k. 注意:由于32位数字和小于95,所以当k>=95时,结果肯定为0. 这样数组就可以开小点,不会超内存!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<cstring>…