lightoj 1036 dp】的更多相关文章

题目链接:http://lightoj.com/volume_showproblem.php?problem=1036 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
A Refining Company LightOJ - 1036 描述好长啊... 题意:在m*n的矩阵上,每一格摆一个向上或者向左的传送带(不能同时摆,只能摆一个).同时,每一格有两种物资Uranium和Radium.会给出两个矩阵,分别表明每一格Uranium和Radium的数量.每一种物资可以通过传送带按照其方向传送,但不能转向(遇到不同方向的传送带物品就失效).Radium要送到上面(第一行任意位置),Uranium要送到左面(左起第一列任意位置),送到错误位置的物资将废弃.求最终送到…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1036 题解:设dp[i][j]表示处理到(i,j)点时的最大值然后转移显然是 dp[i][j] = max(dp[i - 1][j] + asum[i][j] , dp[i][j - 1] + bsum[i][j]); 要么取一整列要么取一整行. #include <iostream> #include <cstring> #include <cstdio…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1036 Description You are given a number 1 ≤ N ≤ 50. Every ticket has its 2 N-digit number. We call a ticket lucky, if the sum of its first N digi…
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25913 思路:易证存在一条从左上角到右下角的折线,沿着格子边缘的...其中处于折线下方的全部运送到左边去,其他运送到上边去...那么这个折线就相当于从上面走到下面得分最大...直接dp就可以. #include<iostream> #include<cstdio> #include<cstring> #include<algorit…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1013 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[i][j]代表刷子下边界为i已用了j次时最大个数.决策为扫和跳过. /** @Date : 2016-12-18 14:25:51 * @FileName: LightOJ 1017 DP?.cpp * @Platform: Windows * @Author : Lweleth (SoundEar…
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.com/ziyi--caolu/p/3236035.html http://blog.csdn.net/hcbbt/article/details/15478095 dp[i][j]为第i天到第j天要穿的最少衣服,考虑第i天,如果后面的[i+1, j]天的衣服不要管,那么dp[i][j] = dp[i…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数,然后求这样的所有的数的欧拉和: 例如 n = 3, p=2; 前两个素数是2,3, 然后因为n=3,所以要再选一个素数组成一个数,有两种选择2*3*2=12 和 2*3*3=18 结果就是Φ(12)+Φ(18) = 10; 我们可以用dp[i][j] 表示前 j 个素数中选择 i 个的结果,Φ[n…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1172 题意:一个n进制(2<=n<=6)的数字,满足以下条件:(1)至少包含两位且不以0开头,比如012是不行的:(2)相邻数字不同:(3)定义这个数字x的score(x)等于相邻数字差的平方和,比如score(125)=(1-2)*(1-2)+(2-5)*(2-5)=10.现在给出n和m,求满足条件的所有n进制的数字中有多少数字的score为m.(1<=m<=10^9…
题意:给你n天需要穿的衣服的样式,每次可以套着穿衣服,脱掉的衣服就不能再穿了,问至少要带多少条衣服才能参加所有宴会 思路:dp[i][j]代表i-j天最少要带的衣服 从后向前dp 区间从大到小 更新dp[i][j]时有两种情况 考虑第i天穿的衣服 1:第i天穿的衣服在之后不再穿了 那么 dp[i][j]=dp[i+1][j]+1; 2:第i天穿的衣服与i+1到j的某一天共用,那么dp[i][j]=min(dp[i][j],dp[i+1][k-1],dp[k][j]),前提是第i天和第k天需要的礼…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1033 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; ;…
题目链接: http://lightoj.com/volume_showproblem.php?problem=1031 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; int dp[maxn][maxn]; //dp[i][j] 表示先手从i到j比后手多的分差. int sum[maxn],a[maxn]; in…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; ; const int INF = 0x3f3f3f3f; double dp[maxn]; int a[maxn]; int main() { //f…
LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/A 题目: Description By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome.…
lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/C 题目: Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two n…
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道状态转移方程和x,没有关系 然后再仔细推导就会知道整个转移方程只和k与y的差值有关 然后继续推导.... 定义dp[i][j]表示表示第j步删除最上边的i点, 定义mv[i]表示删除i点的同时可以向下移动的最远位置(可以预处理出来) 那么dp[i][j]=max(dp[i-1][j],dp[i-mv…
http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间不能涂相同的颜色,每个格子都必须有颜色,问可行的方案数. 分析 经一波分析,根据曼哈顿距离为奇数这一信息,可以将棋盘分为两部分,也就是相邻格子不能有相同颜色.一种颜色只能在一个部分中出现.现在考虑对一个部分的格子操作, dp[i][j]表示i个格子选择用了j种颜色的方案数,于是可以得到这样的递推式:…
hdu 5693 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5693 等差数列当划分细了后只用比较2个或者3个数就可以了,因为大于3的数都可以由2和3组合成. 区间DP,用dp[i][j]表示在i到j之间可以删除的最大数,枚举区间长度,再考虑区间两端是否满足等差数列(这是考虑两个数的),再i到j之间枚举k,分别判断左端点右端点和k是否构成等差数列(还是考虑两个数的),判断左端点,k,右端点是否构成等差数列(这是考虑三个数的) #include<c…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1038 题意是:给你一个N (1 ≤ N ≤ 105) 每次N都随机选一个因子d,然后让N=N/d, 求N变成1的次数的期望: 当 N = 2 时 2有两个因子:1,2 E[2] = E[1]/2 + E[2]/2 + 1;因此可以求出E[2]; 当N = 8 时 8有4个因子1 2 4 8; E[8] = E[1]/4 + E[2]/4 + E[4]/4 + E[8]/4+ 1;因此…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得到该格子的金币.  现在有一个人在1这个位置,手里有一颗骰子,骰子摇到几,他就前进几步,但如果当前位置+骰子数 > n,那么他就会重新摇色子一直到<=n为止. 走到n这个位置的话,意味着游戏结束了. 问游戏结束时,这个人得到金币的期望. 设dp[i]表示从i号格子出去的期望,所以dp[i]是和i后…
B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1422 Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as…
52张扑克牌,问拿到指定数量的4个花色的最少次数期望是多少,其中拿到joker必须马上将其视作一种花色,且要使后续期望最小. 转移很容易想到,主要是两张joker的处理,一个状态除了普通的4个方向的转移,当没拿到joker时还要增加拿到joker的期望,根据题意直接在当前状态下找最小的期望计算即可. /** @Date : 2017-08-29 17:58:59 * @FileName: LightOJ 1364 概率DP.cpp * @Platform: Windows * @Author :…
http://www.lightoj.com/volume_showproblem.php?problem=1032 题意:问1~N二进制下连续两个1的个数 思路:数位DP,dp[i][j][k]代表第i位为j,前面已有k个1的个数. /** @Date : 2016-12-17-13.51 * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Version : */ #include<bits/…
1381 - Scientific Experiment Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lightoj.com/volume_showproblem.php?problem=1381 Description John wants to be a scientist. A first step of becoming a scientist is to perform experiment. John has de…
首先来个期望的论文,讲的非常好,里面也提到了使用线性方程组求解,尤其适用于有向图的期望问题. 算法合集之<浅析竞赛中一类数学期望问题的解决方法> http://www.lightoj.com/volume_showproblem.php?problem=1151 题意:有个1~100个格子的地图,每次投骰子,点数1~6,问到达第100格所需的投骰子次数期望值是多少,注意如果最后走的点数超出了地图,不算完成.地图中有传送门,a b表示从第a格可以到b格. 思路:首先可以想到DP的转移有两种,如果…
A Dangerous Maze (II) LightOJ - 1395(概率dp) 这题是Light Oj 1027的加强版,1027那道是无记忆的. 题意: 有n扇门,每次你可以选择其中一扇.xi为负值的门带你abs(xi)后又回到原点.xi为正值 的门则带你离开迷宫,并且你会记住你前面选择的K道门,在下次选择的时候不会选择这些门.选择每扇门的概率相等.求走出迷宫的时间期望值. 题解: \(定义E[i] 表示记住了K道门后,显然这K道门都是为负值的门,走出迷宫的时间期望值,sum1表示为正的…