light oj 1140 - How Many Zeroes? 数位DP】的更多相关文章

思路:dp[i][j]:表示第i位数,j表示是否有0. 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll long long #define pi acos(-1.0) #define MA…
Jimmy writes down the decimal representations of all natural numbers between and including m and n, (m ≤ n). How many zeroes will he write down? Input Input starts with an integer T (≤ 11000), denoting the number of test cases. Each case contains two…
题意:统计在给定区间内0的数量. 析:数位DP,dp[i][j] 表示前 i 位 有 j 个0,注意前导0. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #inclu…
题目链接: http://acm.hust.edu.cn/vjudge/problem/48419 Odd and Even Zeroes Time Limit: 3000MS 问题描述 In mathematics, the factorial of a positive integer number n is written as n! and is defined as follows: n! = 1 × 2 × 3 × 4 × . . . × (n − 1) × n = ∏n i=1 i…
数位dp,需要记录前导0. 数位dp中需要注意统计0,00,000……这些数字. 数位dp的写法可以分为两类.由于我们通常采用记忆化搜索的方式进行dp,所以我们有一个记忆化数组. 一种是记忆化数组的意义是不通用的,对于不同case,该数组的值不同.另一种是通用的,不同case,数组的值不变. 对于第一种情况的实现比较简单,只需要將递归过程的全部参数记录在数组的维度中. 由于要记录全部的参数,数组维度高,所以空间效率低. 由于不同case要重新计算记忆化数组,所以对于多case的评判时间效率低.…
题目大意: 给你一个n,代表n个数字,现在有两个选手,选手A,B轮流有有一次机会,每个选手一次可以得到一个或者多个数字,从左侧或者右侧,但是不能同时从两边取数字,当所有的数字被取完,那么游戏结束.然后计算每个选手所得到数字的总和,每个选手都尽量让自己的分数比较多,选手A先开始取数.假设每个选手取得数字都是最优的,问A最多比B多多少分数,. 题目分析: 记忆化搜索,区间DP. dp[该谁取了][左区间L][右区间] = 所能取到的最大值. 做下简单的预处理,得到区间L-R之间的和. 然后状态转移…
题目大意: 给你一个base 进制的数字,把这个数字的每一位进行全排列,问有多少个数字是可以整除k的. 题目解析: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namesp…
题目大意: 给你一菱形的数字阵,问从最上面走到最下面所能获得的最大值是多少? #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typedef lo…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1044 dp[i][j]表示i到j直接的最小回文区间个数,直接看代码 #include <bits/stdc++.h> using namespace std; ; int dp[N][N], inf = 1e9; char str[N]; bool judge(int l, int r) { , j = r - ; i < j; ++i, --j) { if(str[i] !…
 找小"3" 序号:#40难度:困难时间限制:1000ms内存限制:10M 描述 给定一个奇数n,可得到一个由从1到n的所有奇数所组成的数列,求这一数列中数字3所出现的总次数.例如当n=3时,可得到奇数列:1,3,其中有一个数字3,故可得1 输入 一个奇数.表示n,0<n<9999999999. 输出 一个整数,表示从 1 到 n 的奇数列中,数字 3 出现的次数. 输入样例 1 3 35 复制样例 输出样例 0 1 7 #include<iostream> #…