CF 2B The least round way DP+Math】的更多相关文章

题意: 找出一条路, 使每个节点相乘,得到的数末尾 0 最少 每次移动只能向右或者向下, 找到后打印路径 ///按照题目要求,就是找出一条从左上角到右下角中每个数含2 or 5 最少的路 ///可以用Dp的思想, 然后把每个节点该走的方向记下来 ///再从终点回溯,把路径存入栈,再输出 ///数据会有0的情况, 这时候我们应该记录离终点最近的0 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef…
Description 有一个n*n的正整数矩阵,要你求一条从第一行第一列的格子到第n行第n列的路,使得你走过的格子里面的数乘起来的值末尾的零的个数最小.输出最小个数. Input 第一行包括1个数n. 接下来n行每行n个数字. Output 一个数字表示末尾零最小个数. Sample Input 3 1 2 3 4 5 6 7 8 9 Sample Output 0 因为都是正数,对这个来说仅仅需统计最少的2或5就可以.相对简单. #include<cstdio> #include<c…
The least round way 题目链接:http://codeforces.com/contest/2/problem/B ——每天在线,欢迎留言谈论.PS.本题有什么想法.建议.疑问 欢迎留言!! 题目大意: ①第一行给你一个n,表示接下来将给你一个n阶方阵的数据 ②要求你从左上方出发到右下方,路径上所有数字乘积 的末尾0的个数最少 ③输出最少0的个数,并输出路径 PS:①每次只能向右或向走 ②D表示向下走,R表示向右 ③0乘任何数的结果 末尾都是一个0: 知识点: ①多个数字相乘,…
题目链接 很久以前就见过此题,以前看了题解,然后今天写了写,写的真搓. #include <cstdio> #include <cstring> #include <string> #include <cmath> #include <ctime> #include <cstdlib> #include <iostream> using namespace std; ][]; ][]; ][]; ][]; ][]; ];…
[cf contest 893(edu round 33)] F - Subtree Minimum Query time limit per test 6 seconds memory limit per test 512 megabytes input standard input output standard output You are given a rooted tree consisting of n vertices. Each vertex has a number writ…
VJ上可找到中文题意. 思路: 首先分解有多少2与多少5.接下来就是dp. 分两次,一次是根据2的数量贪心,另外一次是根据5的数量贪心,看哪一次乘积的末尾0最少. 需要注意的是两点: 1.输入有0的情况,要判断你的ans是不是大于1如果大于1那么输出一条经过0的路径即可. 2.当根据2的数量贪心进行dp的时候,如果可以转移的两个来源的2的数量是相同的,需要找到5的数量较小的状态转移过来. 代码较挫. #include<bits/stdc++.h> using namespace std; ][…
C - Circling Round Treasures 题意: 在一个$n*m$的地图上,有一些障碍,还有a个宝箱和b个炸弹.你从(sx,sy)出发,走四连通的格子.你需要走一条闭合的路径,可以自交,且围出来的复杂多边形内不能包含任何炸弹.你围出来的复杂多边形中包含的宝箱的价值和减去步数就是你的收益.求最大收益.$n,m \le 20,a + b \le 8$ 太坑了课件上的题意有问题一开始没说步数... 后来改上然后$inq[][][]$最后没从$2$改成$S$然后我就看着玄学的$inq$好…
题目链接:http://codeforces.com/problemset/problem/2/B 题目大意: 给你一个nxn的矩形,找到一条从左上角到右下角的路径,使得该路径上所有数字的乘积的末尾0最少.解题思路:我们设k为2的因子数,m为5的因子数,那么一个数的末尾0的个数就是min(k,m).我们设dp[i][j][0]为从左上角到点(i,j)的乘积的最少2因子数,dp[i][j][1]为从左上角到点(i,j)的乘积的最少5因子数.那么ans=min(dp[i][j][0],dp[i][j…
1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径,经过的点数要最多. #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains t…
There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that starts in the upper left cell of the matrix; each following cell is to the right or down from the current cell; the way ends in the bott…
B. The least round way time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that star…
B. The least round way 题目连接: http://www.codeforces.com/contest/2/problem/B Description There is a square matrix n × n, consisting of non-negative integer numbers. You should find such a way on it that starts in the upper left cell of the matrix; each…
http://codeforces.com/problemset/problem/55/D Beautiful Numbers : 这个数能整除它的全部位上非零整数.问[l,r]之间的Beautiful Numbers的个数. 若一个数能整除它的全部的非零数位.那么相当于它能整除个位数的最小公倍数. 因此记忆化搜索中的參数除了len(当前位)和up(是否达到上界),有一个prelcm表示前面的数的最小公倍数.推断这个数是否是Beautiful Numbers,还要有一个參数表示前面数,可是这个数…
题意,给出一个n行m列的矩阵 里面元素是0或者1 给出q个询问 a,b,c,d 求(a,b)到(c,d)有多少个由0组成的矩形 我们定义 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMTc3NTY5MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">即为求(a,b)到(c,d)有多少个由0组成的…
CF EDU 1101D GCD Counting 题意 有一颗树,每个节点有一个值,问树上最长链的长度,要求链上的每个节点的GCD值大于1. 思路 由于每个数的质因子很少,题目的数据200000<2*3*5*7*11*13*17=510510.所以每个节点的质因子个数不多.那么树形DP的时候直接枚举每种因子即可. //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") /…
给定由非负整数组成的n×n 的正方形矩阵,你需要寻找一条路径: 以左上角为起点 每次只能向右或向下走 以右下角为终点 并且,如果我们把沿路遇到的数进行相乘,积应当是最小"round",换句话说,应当以最小数目的0的结尾. Solution 考虑到最终答案只取决于 \(2,5\) 因子数中最小的那一个,所以可以拆开考虑,然后就是一个朴素的最小和路径dp了 注意如果原矩阵中包含零,答案要和 \(1\) 取 min 一下 #include <bits/stdc++.h> usin…
B. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at th…
D. Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two…
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some p…
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then…
一棵树,边长都是1,问这棵树有多少点对的距离刚好为k 令tree(i)表示以i为根的子树 dp[i][j][1]:在tree(i)中,经过节点i,长度为j,其中一个端点为i的路径的个数dp[i][j][0]:在tree(i)中,经过节点i,长度为j,端点不在i的路径的个数 则目标:∑(dp[i][k][0]+dp[i][k][1])初始化:dp[i][0][1]=1,其余为0 siz[i]:tree(i)中,i与离i最远的点的距离递推:dp[i][j][0]+=dp[i][j-l][1]*dp[…
查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记载吧! 求从左上角到右下角所经过的数字之积末端所含0最小的个数 终究的积可以当作A*2^x*5^y,0的个数就是x,y中较小的数, 所以只需要分别dp求出出现2,5的最小个数,再进行比拟,选最小的一个 题目有个陷进: 就是给的数据可认为0,如果出现0的话,经过0这点的话结果为0,就是1个0, 如果不经过0的话,答案可能为0也可能>=1,所以只要求出不经过0出现最小0的个数跟1比拟, 如果大于1的话…
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公倍数是 2520({5,7,8,9}),先预处理出所有可能的最小公倍数m[c] dp[i][d][c]表示长度i, 余数d,各位上的数的最小公倍数是m[c]的个数. #include<cstdio> #include<cstring> #define mod 2520 ll dp[][…
题目大意 给定一个N*N的格子,每个格子里有一个非负数,要求你找出从左上角到右下角的一条路径,使得它满足路径上的格子里的数全部乘起来的积尾部0最少 题解 如果要产生0肯定是2*5得出来的,最终的乘积可以表示为2^x*5^y*C,那么零的个数就是min(x,y).我们可以先对每个格子里的数预处理下,计算出2和5的个数来,然后DP分别求出2和5的最小个数然后选两者中的最小值,输出路径方法没啥说的,很传统~~还有一个要注意的问题就是如果某个格子的数字为0的情况,这个需要特殊判断一下,我们可以把它当做1…
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #inc…
给出1,2,3...m 任取7个互不同样的数a1,a2,a3,a4,a5,a6,a7 一个数的幸运度是数位上4或7的个数 比方244.470幸运度是2. 44434,7276727.4747,7474,幸运度都是4. 求出满足a1,a2,a3,a4,a5,a6,a7这种前6个数的幸运度之和严格小于第七个数的幸运度排列共同拥有多少种 1.先求出数组t t[i]代表1-m中幸运度为i的数的个数. 2.有了t数组后.问题变为一个排列组合问题(枚举a7幸运度.求有多少排列满足前6幸运度之和小于a7幸运度…
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是否所有关系被唯一确定.即任意一次只能有1个元素入度为0入队. #include <iostream> #include <vector> #include <algorithm> #include <string> #include <string.h&g…
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains t…
D. Bash and a Tough Math Puzzle http://codeforces.com/contest/914/problem/D 题意: 单点修改,每次询问一段l~r区间能否去掉小于等于1个数,使gcd为x 分析: 线段树. 线段树二分.如果一边的gcd不是x,那么递归这一边,找到这个位置为止,计算这样的位置的个数. 代码: #include<cstdio> #include<algorithm> #include<cstring> #includ…