hdu_3709_Balanced Number(数位DP)】的更多相关文章

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:给你一个区间,让你找平衡数的个数 题解:设dp[i][j][k]为前i位以第j位为支撑点的力矩和为k的方案数,注意的是0,00,000这些也是平衡数,所以要减掉一个len长度 #include<cstdio> #include<cstring> #define F(i,a,b) for(LL i=a;i<=b;i++) typedef long long LL; LL…
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小于之前的数时,就不用判断i与dig[pos]的大小 // 整体来说就,按位往后移动,每次添加后形成的数都小于之前的数,并且相邻k位不一样,一直深搜到cnt位 // http://blog.csdn.net/weizhuwyzc000/article/details/52097690 // #prag…
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 pre:上一位的奇偶性 status:截止到上一位的连续段的奇偶性 ze:是否有前导0 /************************************************************** Problem:hdu 5898 odd-even number User: yo…
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits:  200000 KB 64-bit interger IO format:  %lld   Java class name:  Main Description A Hill Number is a number whose digits possibly rise and then possibl…
K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation of x is pairwised different.Given (L,R,K), please count how many K-wolf numbers in range of [L,R].   Input   The in…
Accept: 189    Submit: 461Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description One integer number x is called "Mountain Number" if: (1) x>0 and x is an integer; (2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is posit…
Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 3798    Accepted Submission(s): 1772 Problem Description A balanced number is a non-negative integer that can be balanced if a pi…
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful number.问区间[a,b]上有多少个beautiful number.如102就是一个beautiful number,因为它能整除1,2.14不是,因为14不能整除4. 解法: 数位DP,设dp[i][j][k]为累计到第i为,公倍数为j,模lcm(1,2,```,9)=2520的余数为k的数的个…
Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is an integer; (2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists). For exampl…
B. Fi Binary Number     A Fi-binary number is a number that contains only 0 and 1. It does not contain any leading 0. And also it does not contain 2 consecutive 1. The first few such number are 1, 10, 100, 101, 1000, 1001, 1010, 10000, 10001, 10010,…
Problem Description For a number,if the length of continuous odd digits is even and the length of continuous even digits is odd,we call it odd-even number.Now we want to know the amount of odd-even number between L,R(1<=L<=R<= 9*10^18).    Input…
题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的值的奇偶性和长度奇偶性即可. #include <iostream> #include <vector> #include <string.h> #include <stdio.h> #include <queue> using namespace…
分析:赛场上也知道是裸的数位dp,但是无奈刷数位dp题刷的太少了,并不能写出来 一点感想:赛后补题,看了题解的map记录状态,一脸蒙逼,也是非常的不爽,然后想看别人写的,不是递归就是写的比较乱 而且我只刷过最入门的数位dp,例如不要62之类,伤不起啊 然后无奈之下,开了仿照别人题解开了dp[20][10][10][10][10]的数组(别人一般还写个上下限之类的代码,并不能看懂) 这样的数组就可以处理k等于5的情况了,数组第一维代表最高位,后四维代表从当前开始的4个数分别是多少 然后就可以dp[…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5179 题意:给你一个范围,问你漂亮的数有多少个,漂亮的数的定义为 数位高的比数位低的大,并且 数位高的数%数位低的数为0 题解:数位DP,详细看代码,为了方便,我把所有的参数全部设为了状态,这样就不用判断了 #include<cstdio> #include<cstring> #define F(i,a,b) for(int i=a;i<=b;i++) ],len,dp[][][…
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=569&pid=1002 题解: 1.数位dp dp[i][j]表示第i位的数值为j的时候所有合法的情况,转移方程为dp[i][j]+=dp[i-1][k](j%k==0)数位最多为10位,可以离线处理出来. 计算1到x(x十进制按…
题目链接:hdu_5787_K-wolf Number 题意: 给你一个区间,让你找满足任意k个数位内都没有相同的数字的个数 题解: 因为k不大,就直接将当前pos的前k-1个数传进去就行了 #include<cstdio> #include<cstring> ],len,k; ][][][][][]; ) { ; ]][pre[]][pre[]][pre[]][ze]; )return *pp; ; ; ;i<=en;i++){ ,pr[];; ;j<k&&a…
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some…
题目大意: 求  1(m)到n直接有多少个数字x满足 x可以整出这个数字的每一位上的数字 思路: 整除每一位.只需要整除每一位的lcm即可 但是数字太大,dp状态怎么表示呢 发现 1~9的LCM 是2520 ....也就是说只要对这个数mod2520 剩下的余数能整除lcm就可以整除了.. 计数的时候还有一个技巧,具体见注释 此外这个题还卡常数了,预处理lcm才过了.. 代码如下: #include <iostream> #include <stdio.h> #include<…
Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some digit of the nu…
题目链接:hdu_5898_odd-even number 题意: 给你一个区间,问你这个区间中满足连续的偶数的位数为奇数,连续的奇数的位数是偶数的个数 题解: 设dp[i][j][k][l]为考虑当前第i位,上一位的奇偶性为j,已经连续了k位,是否有前导零 然后记忆化搜就行了 #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;++i) using namespace std; typedef long long ll;…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3565 题意:给你一个区间,让你找这个区间内有两个山峰的数的最大和,什么是两个山峰,比如121121  第一个2 和第二个2就是两个峰 题解:求的这个不满足dfs(y)-dfs(x)所以只有用一个上限和一个下限来限制 s=0:前导0的状态: s=1:第一个山峰的上坡,且不能立马下坡: s=2:第一个山峰的上坡,且最后一点能看成是最高点,下一个点可以是下坡: s=3:第一个山峰的下坡: s=4:第二个山…
题意:求区间内有多少个数满足条件:任意相邻的k个数位都不相等. 思路:老套路 #include<bits/stdc++.h> using namespace std; typedef long long ll; ]; ll dp[][][][][][]; bool mycheck(int p[], int k, int newin) { ; i < k - ;i ++) if(p[i] == newin) return false; return true; } ll dfs(int n…
题目链接:https://vjudge.net/problem/HDU-3709 Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 6615    Accepted Submission(s): 3174 Problem Description A balanced number is a non-nega…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题目大意就是求给定区间内的平衡数的个数 要明白一点:对于一个给定的数,假设其位数为n,那么可以有n个不同的位作为支点,但每次只能有一个支点 定义dp[len][pos][k],len表示当前还需处理的位数,pos表示当前的所选的支点的位置,k表示计算到当前的力矩之和(即从最高位到第len+1位) 容易知道如果在某一个len>1的位置k已经小于0,那么就可以直接剪枝 代码如下 : #includ…
题意:  求高位往低位递减且  高位%低位==0(相邻) 数字数量 唯一要注意的就是前导零!!!!!!(正因为这个前导零   一开始的pre设置为0       ) 比如  11  10 09 08 07 06 05 .....说明要判断前导零 #include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b…
题意: 给出求ab之间有多少个平衡数   4139为平衡数   以3为轴   1*1+4*2==9*1 思路很好想但是一直wa  : 注意要减去前导零的情况 0 00 000 0000   不能反复计算 #include<bits/stdc++.h> using namespace std; //input by bxd #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i>…
 Balanced Number Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box wi…
K-wolf Number 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5787 Description Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation of x is pairwised different. Given (L,R,K), please count how many K-wolf…
 Problem Description One integer number x is called "Mountain Number" if: (1) x>0 and x is an integer; (2) Assume x=a[0]a[1]...a[len-2]a[len-1](0≤a[i]≤9, a[0] is positive). Any a[2i+1] is larger or equal to a[2i] and a[2i+2](if exists). For e…
Balanced Number Problem Description A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. More specifically, imagine each digit as a box with weight indicated by the digit. When a pivot is placed at some…