HDU 4507 有点复杂却不难的数位DP】的更多相关文章

首先来说,,这题我wrong了好几次,代码力太弱啊..很多细节没考虑.. 题意:给定两个数 L R,1 <= L <= R <= 10^18 :求L 到 R 间 与 7 无关的数的平方和 什么数与7 无关? 1 没有数字7 2 不是7的倍数 3 所有数字的和不是7的倍数 我们先来考虑一下  如果这题问的是: L 到 R 间 与7 无关的数有多少个? 这道题该怎么思考? 给一点提示  dp 方程可以写成三维的 num(i,j,k) 其中 i 代表数的位数 j 代表 这个数对7取模的余数 k…
Matches Puzzle Game Problem Description As an exciting puzzle game for kids and girlfriends, the Matches Puzzle Game asks the player to find the number of possible equations A−B=C with exactly n (5≤n≤500) matches (or sticks).In these equations, A,B a…
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2422    Accepted Submission(s): 990 Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then careful…
http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 为[A,B] 区间内的数能刚好被其位数和整除的数有多少个. 分析 典型的数位dp...比赛时想不出状态怎么构造,太弱了我. 言归正传,数位和有81种状态,怎么判断当前数字是否被整除呢?可以利用余数的思想,至此,定义状态dp[pos][sum][mod][res]表示前pos位的数位和为sum模mod的结果为res的个数,采用记忆化搜索比较简洁. #include<iostream> #inclu…
题目 传送门:QWQ 分析 数位dp 状压一下现在的$ O(nlogn) $的$ LIS $的二分数组 数据小,所以更新时直接暴力不用二分了. 代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; ; ll dp[maxn][<<][];int k,digit[maxn]; int nextstate(int state,int x){ ;i++){ <<i)){ state^=(&…
X mod f(x) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Here is a function f(x): int f ( int x ) {     if ( x == 0 ) return 0;     return f ( x / 10 ) + x % 10; } Now, you want to know, in a …
Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 9036    Accepted Submission(s): 4294 Problem Description A balanced number is a non-negative integer that can be balanced if a pi…
/* 记忆化搜索,第二维判断是否是6 */ #include<stdio.h> #include<string.h> #define N 9 int dp[N][2],digit[N]; int dfs(int len,int cnt,int ok) {//cnt代表是否是6,ok代表前一个是当前为最大值,并且当前也是最大值 if(!len)return 1; if(!ok&&dp[len][cnt]!=-1)return dp[len][cnt]; int i,a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行,注意每次调用solve函数要初始化dp数组,否则之前调用的时候dp数组可能被记录过. AC代码: #include<iostream> #include<cmath> #include<algorithm> #include<cstdio> #include&…
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字,数组会开不起,该怎么办呢?要用到数位dp. 数位dp一般应用于: 求出在给定区间[A,B]内,符合条件P(i)的数i的个数. 条件P(i)一般与数的大小无关,而与 数的组成 有关. 这样,我们就要考虑一些特殊的记录方法来做这道题.一般来说,要保存给定数的每个位置的数.然后要记录的状态为当前操作数的位数,剩下的…