B-number HDU - 3652】的更多相关文章

hdu 3652 B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string “13” and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your…
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task…
题目链接: Hdu 3652 B-number 题目描述: 给出一个数n,问 [1, n]区间内有几个数能被13整除并且还有13这个子串? 解题思路: 能整除的数位DP,确定好状态随便搞搞就能过了.dp[x][mod][y][z] 表示 x位的整数,mod 13 等于几, y表示是否出现过13, 最后一位是z. 还有就是发现记忆化搜索 + 数位dp写出来真的很美讷.不说了,直接上代码,干净粗暴. #include <vector> #include <cstdio> #includ…
hdu 3652 题意:求1到n中包含'13'('13'不一定连续)且能被13整除的数的个数. 这是我第一道比较了能看懂的数位dp.定义状态dp[pos][res][sta]表示处理到第pos位,模的余数为0,sta取0,1,2,0表示无'13',1表示有1无3,2表示有'13'. 特别注意就是16行只要i==1时,nsta就是1,不用加sta=0,否则会WA.... #include<iostream> #include<cstring> using namespace std;…
Minimum Inversion Number HDU - 1394 求最小反转数,就是求最少的逆序对. 逆序对怎么求,就是先把所有的数都初始化为0,然后按照顺序放入数字,放入数字前查询从这个数往后面的数的位置是不是被占了,被占了说明有逆序对. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm> #define debug(n) printf(&qu…
http://acm.hdu.edu.cn/showproblem.php?pid=3652 题意:求数位含有13和可以被13整除的数字个数. 思路:记录3种状态: st == 0 表示 从最高位到第 i 位既不包含 "13" 末尾也不包含 "1". st == 1 表示 末尾包含 "1". st == 2 表示 从最高位到第 i 位含有 "13". 可以被 13 整除的话用一个参数来记录从最高位到第 i 位的和对 13 取模…
http://acm.hdu.edu.cn/showproblem.php? pid=3652 大致题意:"B-number"即一个整数含有子串"13"且被13整除.求1-n之间这种数的个数. 思路:有两个限制条件:含有子串"13"和能被13整除. 那么设dp[site][mod][flag].表示到第site位对13取余为mod且标记为flag的数的个数.flag表示是否含有子串"13". 然后进行记忆话搜索. #inclu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5062 题目意思:给出 N,找出 1 - 10^N 中满足 Beautiful Palindrome Numbers (BPN)的数量有多少. 满足 BPN 的条件有两个:(1)回文串   (2)对称的部分从左到右递增排放. (1)版本 1 (比较麻烦,建议看版本2)        46ms #include <iostream> #include <cstdio> #include &…
The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we wil…
题意:统计能被13整除和含有13的数的个数 解法没法好说的..学了前面两道直接啪出来了 PS.HDU深夜日常维护,没法交题,拿网上的代码随便对拍一下,输出一致 #include<bits/stdc++.h> #define rep(i,j,k) for(register int i=j;i<=k;i++) using namespace std; const int maxn = 20; typedef long long ll; int a[maxn]; ll r,dp[maxn][2…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5981 题意:A在[L, R]之间随机选取一个数X,之后B来猜这个数,如果猜的数比X小,那么A就告诉B猜小了,如果猜的数大于X,那么以后A永远只会回答B是否猜对了,问在最坏的情况下B至少要猜多少次,并求出有多少种方案. 题解:参考自:https://blog.csdn.net/jaihk662/article/details/77435217     补充关于猜测次数的理解:如果第一次猜测的数大于等于…
As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B. To make the problem easier, I promise that B will be smaller than 100000. Is it too hard? No, I work…
Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, if a positive number n can be expressed byn=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is mjf−good. Otherwise, this positive number is …
题目链接 学习大神的数位DP模版. #include <iostream> #include <cstdio> #include <cstring> using namespace std; ][][]; ]; //dp[i][j][k] 代表前i位余数为j时候 flag的3种情况 int dfs(int pos,int pre,int flag,int bound)//pos代表位置,pre代表余数, { ,end,tflag,tpre,i; )//flag 1代表上…
也是数位dp.考虑反面会简单很多. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ][][],ret=,bit[]; void get_bit(int x) { ret=; ;x/=;} } int dfs(int pos,int mod,int flag1,bool flag2) { if (!pos) retur…
题意:B数的定义是有字符串“13”且能被整数13整除的数,求[1,n]内的B数个数. 题解:这是数位DP,我也就是刚入门,前两天看到了非递归写法,好麻烦.所以我建议写dfs的方法,容易理解,代码还简短. 在这说一下整除13的事,比如1523这个数,你把它用手自己模拟一遍,发现是15先%13==2,之后是(2*10+2)%13==9 ……,以此类推,最后mod==0&&ok==1,才返回1,(ok标记的是 是否出现过“13”). AC代码: #include <map> #inc…
思路:直接打表 #include<cstdio> #include<vector> #include<cmath> #include<iostream> using namespace std; ]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,…
B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3434    Accepted Submission(s): 1921 Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for…
题目链接:B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4911    Accepted Submission(s): 2816 Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decima…
题目大意:若一个数以某个位置为支点,支点左右的加权和相同,这样的数被称为平衡数,求区间内平衡数的个数 思路:枚举支点位置,针对每个支点进行数位DP,但是0比较特殊,假设该数的长度为len,枚举len次支点位置,0会被重复计算len次,但我们只需要统计一次. #include<stdio.h> #include<algorithm> #include<string.h> #include<stdlib.h> #include<iostream> u…
#include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #include<iostream> #include<ctype.h> #include<map> #include<set> #include<string> #include<vector> #include<algorithm>…
题意: 给出范围 算出 满足  选取一个数中任一一个 树作为支点  两边的数分别乘以到中心的距离和 左和等于右和   的数有多少个 数位DP题 状态转移方程为dp[pos][x][state]=dp[pos-1][x][state-(pos-x)*i]  表示为pos位上的数字为 i    以x为支点  则  以中心点左为负右为正   pos左右的数乘以权值的 和为state pos-1位就是 把pos位的 i乘以权值减去   即 state-(pos-x)*i 如果枚举到最后一位的时候 sta…
题目链接:https://cn.vjudge.net/contest/278036#problem/C 题目大意:手首先是T组数据,然后每一次输入两个数l,r,求这个区间里面满足以某个数字为中心的两侧力矩和相等的个数,举个例子,4139,我们如果把3当做对称点,那么力矩和的计算方式= (1-3)*4 + 3*(2-3)+9*(4-3)=0,这个数是满足题目条件的. 具体思路:模板题,我们用一个三维dp储存结果,dp[len][pos][sum],len代表的是当前处理的是第几位,pos代表的是当…
/* 数位dp 题意:找到1-n之间包括13这个子串而且可以整除13的数 解:刚開始dp[N][N][2]这里的2用来记录是否为13表示当前位是否为13,我把上一位为1当前位为13和上一位部位1 这样的情况在数组中没有记录. */ #include<stdio.h> #include<string.h> #define N 14 int dp[N][N][3]; int digit[N]; int dfs(int len,int mod,int cnt,int ok) { if(!…
原以为很好的理解了数位dp,结果遇到一个新的问题还是不会分析,真的是要多积累啊. 解决13的倍数,可以根据当前余数来推,所以把当前余数记为一个状态就可以了. #include<bits/stdc++.h> using namespace std; ][][][]; ]; int dfs(int pos,int preok,int rem,int th,int pre) { ) { &&th==) ; ; } ) return dp[pos][rem][th][pre]; :b[…
题目:求1-n的范围里含有13且能被13整除的数字的个数. 分析: dfs(len, num, mod, flag) mod记录数字对13取余后的值 len表示当前位数 num==0 不含13且上一位不为1 pre==1 不含13且上一位为1 pre==2 含13 flag表示是否可以任意取值(判断范围). 如此,记忆化搜索即可得解. 总结:我是在最后才判断是否可以%13 , 但是这是不可以的 , 经过这道题后,理解更好了 : 这里有个式子特别重要 : 关于连加取mod ,      例如: 1…
题意:找出1~n范围内含有13并且能被13整除的数字的个数 /* 数位DP dp[i][j][0]表示i位数模13为j当前没有包含13并且最高位不为1的方案数: dp[i][j][0]表示i位数模13为j当前没有包含13并且最高位为1的方案数: dp[i][j][0]表示i位数模13为j当前包含13的方案数. */ #include<iostream> #include<cstdio> #include<cstring> #define N 15 using names…
题意: 如果一个整数能被13整除,且其含有子串13的,称为"B数",问[1,n]中有多少个B数? 思路: 这题不要用那个DFS的模板估计很快秒了. 状态设计为dp[位数][前缀][模13][是否含13],前缀这一维还是有必要的(由于只有前缀1和其他不同,所以也可以用01来表示是否前缀为1).递归出口是:出现"13"且mod=0. #include <bits/stdc++.h> #include <iostream> #include <…
[题目链接] 点击打开链接 [算法] 数位DP f[i][j][k][l]表示i位数,第一位为j,除以13的余数为k,是/否包括子串“13”的方案数 当然,我们也可以先打表,然后,对于每次询问,二分即可 [代码] #include<bits/stdc++.h> using namespace std; #define MAXL 13 int i,n; int a[MAXL],r[MAXL]; ][][]; inline void dp() { int i,j,k,x,m; ; i <=…
题目链接:[kuangbin带你飞]专题十五 数位DP G - B-number 题意 求1-n的范围里含有13且能被13整除的数字的个数. 思路 首先,了解这样一个式子:a%m == ((b%m)*c+d)%m; 式子的正确是显然的.就不证明了. 那么推断数能否够被13整除就能够分解为一位一位进行处理. 当然.我们也仅仅须要储存取余后的值. dfs(len, num, mod, flag) mod记录数字对13取余后的值 len表示当前位数 num==0 不含13且上一位不为1 pre==1…