Codeforces #2B The least round way(DP)】的更多相关文章

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: 知识点: ①多个数字相乘,…
题目链接: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…
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; ][…
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…
查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记载吧! 求从左上角到右下角所经过的数字之积末端所含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的话…
题意: 找出一条路, 使每个节点相乘,得到的数末尾 0 最少 每次移动只能向右或者向下, 找到后打印路径 ///按照题目要求,就是找出一条从左上角到右下角中每个数含2 or 5 最少的路 ///可以用Dp的思想, 然后把每个节点该走的方向记下来 ///再从终点回溯,把路径存入栈,再输出 ///数据会有0的情况, 这时候我们应该记录离终点最近的0 #include<bits/stdc++.h> using namespace std; typedef long long LL; typedef…
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory limit 524288 kB Source Technocup 2020 - Elimination Round 2 Tags binary search dp *2200 Site https://codeforces.com/problemset/problem/1225/E 题面 Examp…
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不能超过R才算彻底通关,问直到彻底通关位置的游戏时间的期望值为多少 分析 二分从头开始通关的用时期望mid 设\(dp[i][j]\)表示通前i关,当前时间为j的期望,倒推期望. 若超时重新开始,则\(dp[i][j]…
[Codeforces 553E]Kyoya and Train(期望DP+Floyd+分治FFT) 题面 给出一个\(n\)个点\(m\)条边的有向图(可能有环),走每条边需要支付一个价格\(c_i\),需要的时间为\([1,T]\)中随机的整数,时间为\(j\)的概率为\(p_{i,j}\).从\(1\)出发走到\(n\),如果到\(n\)的时间超过\(T\),就需要再支付\(X\).找出一条路径,使得支付钱数的期望值最小.输出最小期望. \(n \leq 50,m \leq 100,T \…
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/2/B B. The least round way time limit per test 5 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 n…
先算出每个数的pop1(twonum),pop(fivenum)然后DP ans[i][j]表示选i个数有j个2时最多有多少个5 转移方程是 ;j--) { ;w++) { ans[j][w]=max(ans[j][w],ans[j-][w-pop1]+pop); } } AC程序: #include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #in…
C. Travelling Salesman and Special Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he…
Codeforces Beta Round #28 (Codeforces format) 题目链接: http://codeforces.com/contest/28/problem/C 题意: 有 \(n\) 个人,\(m\) 间浴室,每间浴室有\(a[ i ]\)个浴缸,每个人要洗澡的话都要排队,假如一群人进入同一个浴室,他们总倾向于使得最长的队伍最短,现在问你所有队伍中最长的期望? 中文题解: 用状态 \(dp[i][j][k]\) 表示还剩 \(i\) 间浴室,还剩 \(j\) 个人,…
Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2500 的 D1C,可个人认为难度堪比某些 *2700 *2800. 不过嘛,*2500 终究还是 *2500,还是被我自己想出来了 双倍经验 P4448 [AHOI2018初中组]球球的排列 哦 u1s1 其实一年以前做过 P4448,不过好像直到我 AC 这道题之后才发现这俩题一模一样,并且似乎这次用的方法和上次还不太一样 跑题了跑题了 首先有个性质:\(\forall a,b,c\in\mathbb{N}^+\) 若 \(…
D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the seco…
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132014-acmicpc-northwestern-european-regional-contest-nwerc-13-en.pdf D - Diagrams & TableauxA Young diagram is an arrangement of boxes in rows and colum…
题目 Source http://codeforces.com/contest/467/problem/C Description The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced t…
题目链接:http://codeforces.com/contest/451/problem/A 解题报告:有n跟红色的棍子横着放,m根蓝色的棍子竖着放,它们形成n*m个交点,两个人轮流在里面选择交点,选到的交点将把经过这个点的棍子都拿掉,最后没有点可选的人输,另一方赢. n*m个交点不管选哪个点取效果都是一样的,dp[n][m] = !dp[n-1][m-1]   (n > 1 && m >1) #include<cstdio> #include<cstri…
题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k](1<=k<j),由于要求前缀和,可以用树状数组优化 #include<bits/stdc++.h> #define lowbit(x) x&(-x) typedef long long ll; const int N=1e5+3; ll dp[12][N]; using n…
题目链接: http://codeforces.com/contest/161/problem/D D. Distance in Tree time limit per test 3 secondsmemory limit per test 512 megabytes 问题描述 A tree is a connected graph that doesn't contain any cycles. The distance between two vertices of a tree is th…
题目链接:http://codeforces.com/contest/479/problem/E 题意:         给定一个启示的楼层a,有一个不能去的楼层b,对于你可以去的下一个楼层必须满足你当前楼层x与下一个要去的楼层y的距离小于x到b的距离.求出走k趟的方案数. 题解: dp[i][j]  表示第i趟 在第j层楼的方案数.一般用三个for才可以,所以我们用前缀和优化一下,时间复杂度降到O(n*k).空间复杂度有点大,所以我们可以用滚动数组. //#pragma comment(lin…
题目链接:http://codeforces.com/contest/118/problem/D 有n个步兵和m个骑兵要排成一排,其中连续的步兵不能超过k1个,连续的骑兵不能超过k2个. dp[i][j][x][y]表示表示用i个步兵和j个骑兵,末尾有连续的x个步兵,或者有连续的y个骑兵. 所以x > 0 && y > 0的情况不存在.三个for就好了. #include <bits/stdc++.h> using namespace std; typedef lo…
题目链接:http://codeforces.com/contest/712/problem/D A初始有一个分数a,B初始有一个分数b,有t轮比赛,每次比赛都可以取[-k, k]之间的数,问你最后A比B大的情况有多少种. dpA[i][j]表示第i轮获得j分的情况数.因为第i轮只和第i-1轮有关,所以这里i用滚动数组优化. 要是普通做法3个for就会超时,所以要用前缀和优化,dpA[i][j]可以由一段连续的dp[i - 1][x]转移过来,所以用sumA数组存取dp[i - 1][x]的前缀…
题目链接:http://codeforces.com/contest/682/problem/D 给你两个字符串,求两个字符串中顺序k个的相同子串 长度之和.(注意是子串) dp[i][j][k][0] 表示a[i] == a[j]时,a字符串前i个和b字符串前j个,顺序k个相同的子串 长度之和 dp[i][j][k][1] 表示a[i] != a[j]时,顺序k个相同子串的长度之和 dp[i][j][k][0] = max(dp[i - 1][j - 1][k][0], dp[i - 1][j…
题目链接:http://codeforces.com/problemset/problem/710/E 加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少. dp[i]表示i个字符的最小代价. 当i为偶数个的时候,由+1或者*2得到. 当i为奇数个的时候,由+1或者*2-1得到. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm>…
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长度为j的上升子序列个数,但是dp数组是在树状数组的update函数中进行更新. update(i, val, j)函数表示在i的位置加上val,更新dp[i][j]. sum(i, j)就是求出末尾数字小于等于i 且长度为j的子序列有多少个. //#pragma comment(linker, "/…
Word Cut Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 176B Description Let's consider one interesting word game. In this game you should transform one word into another through specia…
题目链接:http://codeforces.com/problemset/problem/337/D 参考博客:http://www.cnblogs.com/chanme/p/3265913 题目大意:给你一个n个点的无向树.任意两点的距离为中间经过的边数.现在某个点上有本魔法书,这本书对与这个点距离小于等于d的点有影响.给你收集到的m个受影响的点(信息不一定全对).要你判断有多少个点可能放魔法书. 算法思路:我参考别人的想法,自己开始怎么也想不出好的算法,n也太大.这题用树形dp,两遍dfs…