hdu 3271 SNIBB 数位DP+二分】的更多相关文章

思路:dp[i][j]:表示第i位在B进制下数字和. 用二分找第k个数! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 using namespace std; ][],…
SNIBB Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 327164-bit integer IO format: %I64d      Java class name: Main     As we know, some numbers have interesting property. For example, any even number has th…
/** 题目:poj3208 Apocalypse Someday 链接:http://poj.org/problem?id=3208 题意:求第K(K <= 5*107)个有连续3个6的数. 思路:数位dp+二分. dp[i][j]表示长度为i,前缀状态为j时含有的个数. j=0表示含有前导0: j=1表示前缀连续1个6 j=2表示前缀连续2个6 j=3表示前缀连续3个6 j=4表示前缀不是6: */ //#include<bits/stdc++.h> #include<cstr…
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49&…
1.HDU 2089  不要62    简单数位dp 2.总结:看了题解才敲出来的,还是好弱.. #include<iostream> #include<cstring> #include<cstdio> using namespace std; ][]; //dp[i][j]表示以j为首位符合条件的i位数的个数 void init() //预处理 { memset(dp,,sizeof(dp)); dp[][]=; ;i<;i++){ ;j<;j++){…
题目链接: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…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3555 Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) 问题描述 The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bo…
题目链接: http://hihocoder.com/problemset/problem/1301?sid=804672 题解: 二分答案,每次判断用数位dp做. #include<iostream> #include<cstring> #include<cstdio> using namespace std; typedef long long LL; const LL INFLL = 0x3f3f3f3f3f3f3f3fLL; //dp[x][0]表示高位还没有出…
题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~b有多少个不大于f(a)的数. 思路: 数位DP,用来学习数位DP了. <数位DP> 所谓数位DP就是基于考虑数字的每一位来转移的DP. 例如求比456小的数,可以这么考虑, 4          5               6   4       5             (0~6) 4…
积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要搞错. 传送门:http://acm.upc.edu.cn/problem.php?id=2223 题意: 能被7整除或者含7的数称为A-Number,所有A-Number从小到大写好,下标编号(从1开始),去掉那些下标为A-Number的数,剩下的数称为B-Number.求第N个B-Number是多少. 思…
All submissions for this problem are available. Chef likes numbers and number theory, we all know that. There are N digit strings that he particularly likes. He likes them so much that he defines some numbers to be beautiful numbers based on these di…
### HDU 6148 题目链接 ### 题目大意: 众所周知,度度熊非常喜欢数字. 它最近发明了一种新的数字:Valley Number,像山谷一样的数字. 当一个数字,从左到右依次看过去数字没有出现先递增接着递减的“山峰”现象,就被称作 Valley Number.它可以递增,也可以递减,还可以先递减再递增.在递增或递减的过程中可以出现相等的情况. 比如,1,10,12,212,32122都是 Valley Number. 121,12331,21212则不是. 度度熊想知道不大于N的Va…
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;…
题目链接 学习大神的数位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代表上…
给出n,问所有[0,n]区间内的数中,不含有49的数的个数 数位dp,记忆化搜索 dfs(int pos,bool pre,bool flag,bool e) pos:当前要枚举的位置 pre:当前要枚举的位置的前面是否为4 flag:枚举当前时,这个数的49时候被算过了 e:当前位置是否可以随便取值 dp[pos][pre][flag] #include<cstdio> #include<cstring> #include<algorithm> #include<…
/* 题意:求出p-q的第j个nya数 数位dp,求出p-q的所有nya数的个数很好求,但是询问求出最终那个第j个值时是我不会求了看了下别人的思路 具体就是把p-q的第j个转化成0-q的第low+j个(其中low为小于等于p的nya数) 枚举q的每一位数字,枚举位数值并进行比较直至求出每一位的值. 经典好题,长见识了. */ #include<stdio.h> #include<string.h> #define ll __int64 #define N 21 ll dp[N][N…
题目链接:[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…
数位dp解决的问题是指求在一段数的区间里面 满足条件的数的个数 核心为两点 http://wenku.baidu.com/link?url=tpfIYzhx_MzevpIM58UZ66pr-87MCFPKTMKFdGDi5jUqyO9ckti0mY6diSz2PZEL_ZBhd2zIbhus1mnzDiAO1B5K2Vu38YDsqjmOvYKFT6q 我自己总结下吧 第一 是dp的状态转移方程 dp[i][j] 表示的是以j开头的i位数 满足条件的个数为多少 既然是要记录满足条件的个 那么 d…
SNIBB Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1485    Accepted Submission(s): 435 Problem Description   As we know, some numbers have interesting property. For example, any even number h…
意甲冠军:有两个查询: q=1.在[x,y]间隔,兑换b十进制,数字和m多少个月. q=2.在[x,y]间隔,兑换b十进制,数字是m第一k的数目是多少(十进制),没有输出由给定的主题. 思维: 和比特的平均数dp如,第几个数的话就是二分推断. 然后就是按常理要开4维,就是dp[i][sum][b][m] i位,和为sum,b进制,最后和为m 可是开不下,所以开3维每次初始化. 注意一下: 1.每次都要初始化 2.x不一定小于y 3.是[x,y]不是(x,y] 代码: #include"cstdl…
K-th Nya Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 3155    Accepted Submission(s): 1021 Problem Description Arcueid likes nya number very much.A nya number is the number which has…
题意:给一个数q, q=1时求给定区间,给定进制,各数位和等于m的数字的个数 q=2时求给定区间,给定进制,各数位和等于m的数字中的第k大的数字 分析:dp[i][sum][j],表示长度为i当前数位和是sum,进制是j的个数,q=2时用二分求出k大数 题意给的区间[x,y],x不一定小于y,给定区间没k大数,则输出 Could not find the Number! #include <map> #include <set> #include <list> #inc…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5898 题意:很明确,找出区间[l , r]中符合连续奇数为偶数,连续偶数为奇数的个数. 思路:dp[i][j][1]表示i位数j开头符合条件的数,dp[i][j][0]表示i位数j开头(之后)可能符合条件的数. #include<cstdio> #include<cstring> using namespace std; typedef long long ll; ll dp[22][…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2089 不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 34901    Accepted Submission(s): 12664 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoe…
[HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[20]; __int64 dp[20][11]; void digit_dp() { memset(dp, 0LL, sizeof(dp)); dp[0][0]=1; for(int i=1; i<20; ++i)…
要求m-n内在l-r进制下的是回文数的总个数. dp[进制][从第j为开始][目前到达第k位] = 总的方案数 dfs枚举目前的到达的位置,这个数开始的位置,进制,前导零,限制条件,然后枚举的时候如果我现在是总的数的前一半,那么我就可以随意枚举,如果我已经到这个数的后一半了,那么我枚举的数字应该要满足和前面一半的这个位置对应的数,否则的话就是不满足条件的回文数,用这个数开始的位置为0来表示这个数不满足条件或者说我枚举的这个数全部都是零.然后算出这个区间内的回文数,要求sumf(i, j), 那么…
题目链接: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[pos][pre]代表长度为pos的不大于pre的个数 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<queue> #include<set> #include<vector> #include<map> #include<stack> #include<cmath&…
题目链接:https://vjudge.net/problem/38405 #include<bits/stdc++.h> using namespace std; ][]; ]; long long dfs(int pos,int preok,int pre1) { ) ; ) return dp[pos][pre1]; :b[pos]; ; ; ;i<=up;i++) { ,,i==); ,,i==); } if (preok) dp[pos][pre1]=ans; return a…