Mountain Number FZU-2109数位dp】的更多相关文章

Number 题目背景 SOURCE:NOIP2015-SHY-10 题目描述 如果一个数能够表示成两两不同的 3 的幂次的和,就说这个数是好的. 比如 13 是好的,因为 13 = 9 + 3 + 1 . 又比如 90 是好的,因为 90 = 81 + 9 . 现在我们用 a[i] 表示第 i 小的好数. 比如 a[1] = 1, a[2] = 3, a[5] = 10 . 给定 L,R,请求出 a[L] 到 a[R] 的 和 mod 232. 输入格式 第一行一个整数 T,表示数据组数. 接…
题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We consider a positive integer perfect, if and only if the sum of its digits is exactly 1010. Given a positive integ…
题意: 给出范围 算出 满足  选取一个数中任一一个 树作为支点  两边的数分别乘以到中心的距离和 左和等于右和   的数有多少个 数位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…
#include<stdio.h> #include<string.h> #define N 20 #define ll __int64 ll dp[N][N];//最多记忆400种情况 ll digit[N]; ll dfs(ll len,ll cnt,ll ok) { if(!len) return cnt; if(!ok&&dp[len][cnt]!=-1) return dp[len][cnt]; ll i,ans=0,maxx=ok?digit[len]:…
题面 给定整数m,km,km,k,求出最小和最大的正整数 nnn 使得 n+1,n+2,-,2nn+1,n+2,-,2nn+1,n+2,-,2n 中恰好有 mmm 个数 在二进制下恰好有 kkk 个 111.如果有无数个满足条件则输出一行一个整数−1-1−1.有TTT组数据. T≤2000T\le 2000T≤2000 m≤1e18m\le 1e18m≤1e18 k≤64k\le 64k≤64 保证1e181e181e18内 存在一个数满足条件. 题解 设f(i)f(i)f(i)表示i+1,i+…
传送门: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…
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…
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…
http://acm.fzu.edu.cn/problem.php?pid=2109 题意:找出区间[l,r]内满足奇数位的数字大于相邻偶数位数字的个数. 典型的数位dp了,记录一下当前位是奇数位还是偶数位. 状态设计为到当前位为(奇数还是偶数的条件下上一位数字为x的)满足条件的 个数. #include<cstdio>#include<cstring>#include<algorithm>;];;        ;    }    ;    ; ;    ;i<…
Mountain NumberFZU-2109 题目大意:一个大于0的数字x,分写成x=a[0]a[1]a[2][3]..a[n]的形式,(比如x=1234,a[0]=1,a[1]=2,a[3]=3,a[3]=4),Mountain Number要满足对于a[2*i+1]要大于等于a[2*i]和a[2*i+2],给定范围l,r问,有多少个Mountain Number 就简单的数位dp,照着题意写就行,而且求的是数字,前导0并没有任何影响,对于全0的情况,我们把0也特别视为Mountain Nu…
 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…
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…
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…
 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…
// 多校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…
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…
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…
Round Numbers Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6983   Accepted: 2384 Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors',…
题目链接: 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的数的个…
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 number, the distance f…
每一位都大于等于前一位的数叫Ramp Number 给一个数,如果不是Ramp Number输出-1,如果是Ramp Number输出比它小的Ramp Number的个数 只和每一位上的数字有关 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <queue> #include &l…
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…
beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 801    Accepted Submission(s): 518 Problem Description Let A=∑ni=1ai∗10n−i(1≤ai≤9)(n is the number of A's digits). We call A as “…
LINK:Number of Binominal Coefficients 原来难题都长这样.. 水平有限只能推到一半. 设\(f(x)\)表示x中所含p的最大次数.即x质因数分解之后 p的指标. 容易想到 \(f(n!)=\sum_{i=1}^{n}\frac{n}{p^i}\) 也同时 题目其实是想让我们求出 \(f(n!)-f(k!)-f((n-k)!)>=a\)的数对(n,k)的个数. 需要再转换一下 可以得到\(f(x)\)x质因数分解之后扔掉第一位的数字大小. \(f(n!)\)其实…
题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++.h> typedef long long ll; const int N = 70 + 5; char str[N]; ll dp[N][10][2]; int len; ll DFS(int pos, int pre, int up, int limit) { if (pos == len) { re…
题目链接 题意:一个数字,它每个数位上的奇数都形成偶数长度的段,偶数位都形成奇数长度的段他就是好的.问[L , R]的好数个数. 题解:裸的数位dp, 从高到低考虑每个数位, 状态里存下到当前位为止的值的奇偶性和长度奇偶性即可. #include <iostream> #include <vector> #include <string.h> #include <stdio.h> #include <queue> using namespace…
题目要求第k个没有连续两个1的二进制数. 这算数位DP吧,只不过以前遇到的是统计区间的数字情况,而这题是求第几个数字,差不多是反过来的. 本来我想用状态dp[i][0/1]表示长度i末尾0或1的二进制数个数,发现这样好像没法解. 最后需要根据数位DP状态的值推算出要求二进制数各个位置是0还是1,这个肯定是从高位到低位确定——所以应该反过来表示状态: dp[i][0/1]:长度i开头为0或1的二进制数个数 最后的求解: 先利用dp[i][1]的值确定出要求二进制的位数 位数知道后,最高位得是1 最…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:求区间[L,R]内每一个数中是否存在一位,使得左边的各位数*距离=右边的各位数*距离(自己和自己的距离算0). 先枚举pivot的位置,然后做数位dp,记录当前数位.pv的位置和当前和.由于前导零的存在,最后结果要减掉诸如00,000,000...0这样的情况(个数和数位长度相同,当然单独一个0是合法的). 最终结果ret-pos+1 #include <bits/stdc++.h>…