nowcoder A hard problem /// 数位DP】的更多相关文章

题目大意: 称一个数x的各个数位之和为f(x) 求区间L R之间 有多少个数x%f(x)==0 #include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define LL long long #define inc(i,j,k) for(int i=j;i<=k;i++) #define dec(i,j,k) for(int i=j;i>=k;i--) #define gcd(i,j) __gcd(…
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位dp了.只是貌似正解是o(n)的算法.可是n才 1000.用o(n^2)的复杂度也是够的. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long…
题目链接:http://hihocoder.com/problemset/problem/1259 题目大意:g(t)=(f(i)%k=t)的f(i)的个数 求所有的(0-k-1)的g(i)的异或总值 思路:首先推出公式3*f(n)*f(2n+1)=f(2n)*(1+3f(n)) 3f(n)和3f(n)+1相邻的两个数肯定是互质的 所以解出f(2n)=3*f(n) f(2n+1)=3*f(n)+1 相当于是n表示成2进制但是每位的权值为3 然后就是数位dp的过程了 dp[k][i][j] k表示…
链接:https://ac.nowcoder.com/acm/contest/554/G Now we have a function f(x): int f ( int x ) {     if ( x == 0 ) return 0;     return f ( x / 10 ) + x % 10; } For a given interval [A, B] (1 <= A <= B <= 10^9), calculate how many integer x that mod f…
The Counting Problem Description 求 [L,R]内每个数码出现的次数. Input Format 若干行,一行两个正整数 L 和 R. 最后一行 L=R=0,表示输入结束. Output Format 若干行,对于每个询问做出回答,每行 10 个整数,依次表示 0 至 9 出现的次数. 输入的最后一行不属于询问,因此不必对此做出回答. Sample Input 1 10 114 514 233 666 19260421 19260817 19190504 1989…
题意:统计l-r中每种数字出现的次数 很明显的数位dp问题,虽然有更简洁的做法但某人已经习惯了数位dp的风格所以还是选择扬长避短吧(说白了就是菜啊) 从高位向低位走,设状态$(u,lim,ze)$表示当前走到了第几位,是否有上限,是否有前导零的状态,则问题转化成了求所有转移路径中经过的所有数字的数量统计问题. 设$f[u][lim][ze]$为从状态$(u,lim,ze)$向后走能到达的状态总数,$g[u][lim][ze][i]$为状态$(u,lim,ze)$及其向后走能到达的所有状态中数字$…
Description Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be 1024 1025 1026 1027 1028 10…
Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/B Description Little John studies numeral systems. After learning all about fixed-base systems, he became inte…
传送门 数位dp卡常题. 写了一发dfs版本的发现过不了233. 于是赶紧转循环版本. 预处理出f数组. f[i][j]f[i][j]f[i][j]表示前i位数异或和为j的方案数. 然后每次直接数位dp就行了. 代码: #include<bits/stdc++.h> #define mod 1000000007 #define N 100005 #define ll long long using namespace std; ll f[N][16],ans[16]; inline void…
链接:https://ac.nowcoder.com/acm/contest/897/L 来源:牛客网 XOR 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 Exclusive or is a logical operation that outputs true only when inputs differ(one is true, the other is false). It is…
不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 36862    Accepted Submission(s): 13418 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可…
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字,数组会开不起,该怎么办呢?要用到数位dp. 数位dp一般应用于: 求出在给定区间[A,B]内,符合条件P(i)的数i的个数. 条件P(i)一般与数的大小无关,而与 数的组成 有关. 这样,我们就要考虑一些特殊的记录方法来做这道题.一般来说,要保存给定数的每个位置的数.然后要记录的状态为当前操作数的位数,剩下的…
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 pre:前一位是什么 status:是否有前导零 递增递减差不多思路,不过他们计算的过程中像5555,444 这样的重复串会多算,所以要剪掉.个数是(pos-1)*9+digit[最高位],比如一位重复子串是:1,2,3,4...9,9个,二位重复子串:11,22,33,44,...,99,9个:…
传送门: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…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 13181    Accepted Submission(s): 4725 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorist…
不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 31547    Accepted Submission(s): 11172 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,…
http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7316    Accepted Submission(s): 2551 Problem Description The counter-terrorists found a time…
SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 and 7 are lucky and all others are not. According to them, an almost lucky number is a number that contains at most one non-lucky digit in its decimal…
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…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 思路:数位dp, 采用记忆化搜索, dp[pos][pre][have] 表示 pos处,前一位为pre, 当前有have个满足条件的状态. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]…
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…
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…
B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5000    Accepted Submission(s): 2866 Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for…
有一类与数位有关的区间统计问题.这类问题往往具有比较浓厚的数学味道,无法暴力求解,需要在数位上进行递推等操作.这类问题往往需要一些预处理,这就用到了数位DP. 本文地址:http://www.cnblogs.com/archimedes/p/numerical-digit-dp.html,转载请注明源地址. 基础知识 [l,r] 意为 l<=且<=r的数 [l,r) 意为 l<=且< r的数 (l,r] 意为 l<且<=r的数 (l,r) 意为 l<且< r…
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1026 分析: 简单的数位DP啦 f[i][j]表示数字有i位,最高位的数值为j的windy数总个数 那么f[i][j]=singma(f[i-1][k])(|j-k|>=2) 那么对于1~x(假设x从高到低的每位依次是x[n],x[n-1],……x[1])中的windy数个数就是f[n][0]+f[n][1]+……f[n][x[n]-1] + f[n-1][0]+f[n-1][1]+……f[…
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. 首先要求能被各位上的数整除,可以转化为被一个数整除问题. 这个数就是各位上数的最小公倍数LCM(不是GCD). 其次,处理整除问题,得转化成数位DP的余数模板.1~9的LCM最大是2520, 那么%2520,让其可以开数组进行记忆化搜索. 最后, 对于不能%2520最后结果,再%各个数位累计过来的…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 15372    Accepted Submission(s): 5563 Problem Description The counter-terrorists f…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4734 F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4389    Accepted Submission(s): 1614 Problem Description For a decimal number x with…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 7921    Accepted Submission(s): 2778 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists…
Contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 220    Accepted Submission(s): 88 Problem Description In the ACM International Collegiate Programming Contest, each team consist of three…