poj3373Changing Digits(dp)】的更多相关文章

链接 dfs倒着搜 返回的路径不能满足相同的数最多 借鉴了下别人的代码.. 先dp出来 再倒着标记一下 然后正回来一定可以满足了 dp保存的是最小的不相同数 #include <iostream> #include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm> using namespace std; #define INF 0xfffffff ][]; ]; ]…
题目链接 隔了一年零三个月,重新刷URAL,这题挺麻烦的输出路径.输出路径挺扯的,乱写了写乱改改就A了...我本来想用很靠谱,记录每一条路径的,然后输出最小的,结果Tle,然后我使劲水水又过了一组,发现别人的题解..直接来了一次 就过了..我乱搞了搞,倒着记录最小的,然后倒着输出,就过了... #include <cstring> #include <cstdio> #include <string> #include <iostream> #include…
题目链接 记录路径的DP,看的别人的思路.自己写的也不好,时间居然2000+,中间的取余可以打个表,优化一下. 写的各种错,导致wa很多次,写了一下午,自己构造数据,终于发现了最后一个bug. dp[i][j]表示前i位取余得到j,需要最少改变多少位. 这样可以得到最少改变多少位了,但是,还要保证,最小.学习别人的题解,开一个标记数组,先从后倒回来,把这些可以达到最小的路径都记录下来. 然后再从头找最小的那一条路径.这样就能保证,最小了. #include <cstdio> #include…
链接 这题卡了挺久了 昨天试着用类似dfs的方法直接TLE在第二组 看了下题解,,发现s1,s2的范围是个幌子..100位最大的s1900 s28100 觉得s1s2太大不敢开二维.. 这样就简单了 类似背包 dp[s1][s2]表示组成s2s2最少的位数 其实就是装进去多少个数字 正好把s1s2装满 把DP部分预处理之后放在外面  不然会超时 #include <iostream> #include<cstdio> #include<cstring> #include…
题目链接:点击打开链接 题目大意:给出一个n和一个k 求m 要求1.m要和n相同的位数 要求2.m要整除k 要求3.如果1和2满足,那么m要和n有尽量少的不同位 要求4.如果1.2.3满足,要使m尽量的小 简单的一个深搜,但是直接被要求吓蒙,,,,, 要求1和2直接可以在搜索时判断,要求3可以在深搜时给出可以改变的位数(有0到len(n)),而要求4需要控制在搜索是要从小的开始搜,即从100000到999999,因为在深搜之前就控制了可以改变的次数,所以在搜索时不用担心要求3,只要使要求1要求2…
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 100, excluding [11,22,33,44,55,66,77,88,99]) Analysis: A num…
http://codeforces.com/contest/747/problem/F cf #387 div2 problem f 非常好的一道题.看完题,然后就不知道怎么做,感觉是dp,但是不知道怎么枚举.还有就是一般求第k小的思路一般是什么?对这类题目理解的不是很好. 这道题,跟上一篇的题解里面写的hdu 1002 递增数的题目的解法差不多,但是底层的求解需要花一些时间去推敲! 不会做,就看官方题解,看不懂说的什么.就从下面的讨论找大神的题解. I can describe my solu…
一.小数精度的设置 一般在设置-数据结构-精度设置中就可以对 小数类型的字段进行精度设置: 对于代码中定义为 digits=dp.get_precision('Product Price') 或 digits_compute=dp.get_precision('Account') 形式的字段均可以奏效. 二.货币参数 Odoo中有一类字段Monetary用于计算跟货币相关的运算,定义为Monetary的字段需要与货币(Currency_id)关联计算. 货币的设置位于 设置-公司-配置-财务-货…
这是一个向导 A - hdu 3652 B - bzoj 4152 C - bzoj 2429 D - bzoj 1087 E - bzoj 1566 F - bzoj 4043 G - bzoj 1052 H - bzoj 2957 I - bzoj 2463 J - bzoj 2190 Problem A  B-number 题目大意 求1到n中包含连续子串"13"的数且能被13整除的数有多少个. ->题目传送站[here] 不难想到数位dp,现在开始设计状态.包含子串&qu…
python round() 函数     Python用于四舍五入的内建函数round() ,它的定义为 意思是, 将 小数部分保留到 ndigits 指定的 小数位,也就是 精度保持到 ndigits -1 位: 如果没有 指定 ndigits ,则 精度 保持到 整数位.     例如     n = 5.11965811966 直接 round 时, 精确度 为整数, 即 5.0 : round(n, 5)时,小数位保留 5位,即 5.11966         odoo小数位数设置  …
题目要求: 给定一个数字,按照如下规则翻译成字符串:0翻译成“a”,1翻译成“b”...25翻译成“z”.一个数字有多种翻译可能,例如12258一共有5种,分别是bccfi,bwfi,bczi,mcfi,mzi.实现一个函数,用来计算一个数字有多少种不同的翻译方法. 解题思路: 下面我们从自上而下和自下而上两种角度分析这道题目,以12258为例: 自上而下,从最大的问题开始,递归 : 有很多子问题被多次计算,比如258被翻译成几种这个子问题就被计算了两次. 自然想到可以用动态规划来解决,用f(i…
罗列一些odoo开发中的简单但有效的方法: 1.重写odoo登录代码 参考链接:odoo10-重写登录方法 from odoo import models, fields, api, SUPERUSER_ID class Users(models.Model): _inherit = "res.users" @classmethod def _login(cls, db, login, password): user_id = super(Users, cls)._login(db,…
Clarke and digits 问题描述 克拉克是一名人格分裂患者.某一天,克拉克变成了一个研究人员,在研究数字. 他想知道在所有长度在[l,r]之间的能被7整除且相邻数位之和不为k的正整数有多少个. 输入描述 第一行一个整数T(1≤T≤5),表示数据的组数. 每组数据只有一行三个整数l,r,k(1≤l≤r≤109,0≤k≤18) 输出描述 每组数据输出一行一个数,表示答案.由于答案太大,你只需对10^9+7取模即可. 输入样例 2 1 2 5 2 3 5 输出样例 13 125 Hint…
Clarke and digits Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Clarke is a patient with multiple personality disorder. One day, Clarke turned into a researcher, did a research on digits. He w…
4877 Non-Decreasing Digits A number is said to be made up ofnon-decreasing digitsif all the digits to theleftof any digit is lessthan or equal to that digit. For example, the four-digit number 1234 is composed of digits that arenon-decreasing. Some o…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5564 题意: 求长度在[L,R]范围,并且能整除7的整数的总数. 题解: 考虑最原始的想法: dp[i][j][k]表示长度为i,并且对7取模得到j的以k结尾的数. 则有状态转移方程dp[i+1][(h*10)+l)%7][k]+=dp[i][h][k'](k+k'!=K). 但是i范围是1~10^9,需要矩阵加速. 这里对dp[i][j][k]的[j][k]两个状态进行压缩,得到转移矩阵mat[…
一開始写的高位往低位递推,发现这样有些时候保证不了第四条要求.于是又開始写高位往低位的记忆化搜索,又发现传參什么的蛋疼的要死.然后又发现高位開始的记忆化搜索就是从低位往高位的递推呀,遂过之. dp[i][j]记录在i位 且 余数为j时的最优解情况. dp[i][j].next表示当前的最优解是由哪一种状态转移过来的. 代码又写锉了.. #include <algorithm> #include <iostream> #include <cstring> #include…
传送门 好题啊. 我只会写l,rl,rl,r都很小的情况(然而题上并没有这种数据范围). 但这个dp转移式子可以借鉴. 我们用f[i][j][k]f[i][j][k]f[i][j][k]表示当前在第i位,模7余j,当前位是k. 显然有f[i+1][([j∗10+l)f[i+1][([j*10+l)f[i+1][([j∗10+l)%7][l]+=f[i][j][k]7][l]+=f[i][j][k]7][l]+=f[i][j][k]. 但是i上限1e91e91e9,直接做会凉. 于是我们构造矩阵来…
Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4307   Accepted: 1894 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must…
在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字,数组会开不起,该怎么办呢?要用到数位dp. 数位dp一般应用于: 求出在给定区间[A,B]内,符合条件P(i)的数i的个数. 条件P(i)一般与数的大小无关,而与 数的组成 有关. 这样,我们就要考虑一些特殊的记录方法来做这道题.一般来说,要保存给定数的每个位置的数.然后要记录的状态为当前操作数的位数,剩下的…
题目链接 http://lightoj.com/volume_showproblem.php?problem=1031 Description You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more nu…
C. Efim and Strange Grade time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any po…
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…
Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5020   Accepted: 1355 Description YYF is a couragous scout. Now he is on a dangerous mission which is to penetrate into the enemy's base. After overcoming a series difficulties,…
Zero Escape Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 289    Accepted Submission(s): 135 Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchiko…
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…
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…
Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3929   Accepted: 1761 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must…
http://acm.split.hdu.edu.cn/showproblem.php?pid=3076 ssworld VS DDD Problem Description   One day, sssworld and DDD play games together, but there are some special rules in this games.They both have their own HP. Each round they dice respectively and…