摘要: 地址:https://www.acwing.com/problem/content/284/ 题意:给一堆石子,相邻的合并,问最后得到的最小花费,花费具体算法在题里。 解析: 对于此题,根据常识,对于最终状态,是由两团合并的。所以定义dp[i][j]表示区间i-j合并的最小值。 二堆合并:dp[1] 阅读全文
posted @ 2020-04-11 23:44 liyexin 阅读(185) 评论(0) 推荐(0)
摘要: 地址:https://cometoj.com/contest/76/problem/A?problem_id=4237 解析:这个题用DP解比较简单,其他的解法我并没有看懂。所谓波浪,单独一个数字不能算,两个数字一定算上。我们的二维dp,j=0表示下降或相等,j =1 表示上升。i 从0到n 转移方 阅读全文
posted @ 2020-04-11 23:41 liyexin 阅读(168) 评论(0) 推荐(0)
摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1087 题意:这个样例很误导人啊,这个题意呢,就是从起点跳到终点,保持递增跳而且得分最大。注意,起点和终点是不计分的; 解析:模板改一下就好了,之前求的是序列长度。这里求和,那么只要把dp初始化a[ ],依然 阅读全文
posted @ 2020-04-11 23:38 liyexin 阅读(203) 评论(0) 推荐(0)
摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1257 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const 阅读全文
posted @ 2020-04-11 23:36 liyexin 阅读(116) 评论(0) 推荐(0)
摘要: 地址:http://codeforces.com/problemset/problem/455/A Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winte 阅读全文
posted @ 2020-04-11 23:35 liyexin 阅读(178) 评论(0) 推荐(0)
摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1176 中文题意不多解释了。 建一个二维dp数组,dp[ i ][ j ]表示第 i 秒落在 j 处一个馅饼。我们需要倒着DP,为什么呢,从 0秒,x=5处出发,假如沿数组正着往下走,终点到哪里我们是不知道的 阅读全文
posted @ 2020-04-11 23:34 liyexin 阅读(133) 评论(0) 推荐(0)
摘要: 之前就已经学过了,放在了本地,现在搬到博客园来~ 关于线段树的视频学习,强烈推荐B站此大佬的讲解:https://www.bilibili.com/video/BV1cb411t7AM 1.概念:线段树是一种二叉搜索树,与区间树相似。线段树是建立在线段或区间基础上的树,树的每个结点代表一条线段[L, 阅读全文
posted @ 2020-04-11 23:17 liyexin 阅读(141) 评论(0) 推荐(0)
摘要: 地址:http://codeup.cn/problem.php?id=5974 题目描述 已知 n 个整数b1,b2,…,bn 以及一个整数 k(k<n)。 从 n 个整数中任选 k 个整数相加,可分别得到一系列的和。 例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合 阅读全文
posted @ 2020-04-11 16:51 liyexin 阅读(321) 评论(0) 推荐(0)
摘要: #include<iostream> #include<cstring> using namespace std; const int maxn=1e3; int vis[maxn]; int p[maxn]; int n; int t=0; void dfs(int x) { if(x==n+1) 阅读全文
posted @ 2020-04-11 16:49 liyexin 阅读(136) 评论(0) 推荐(0)
摘要: 和ACWING 844基本一样。但是这里要输出路径 我的做法是,pair一个ing[x][y],ing[x][y].first,ing[x][y].second记录x,y的前一个点。因为是逆序,所以又存进一个结构体里,再逆序输出,才变成正序了。 #include<iostream> #include 阅读全文
posted @ 2020-04-11 16:48 liyexin 阅读(131) 评论(0) 推荐(0)
摘要: 地址:https://www.acwing.com/problem/content/846/ 走迷宫,从左上角走到右下角,0可走,1不可走,问最少需要几步。 BFS解法: 通过g[][]记录地图,d[][]初始化为-1用来保证一个点只能走一次以及记录每个点到达终点的距离。 注意:使用以下语句来实现队 阅读全文
posted @ 2020-04-11 16:46 liyexin 阅读(251) 评论(0) 推荐(1)
摘要: ACWING板子题地址:https://www.acwing.com/problem/content/description/845/ 题中已经说的很清楚了,什么叫n皇后。对于一个棋子的摆放,我们应该保证这个棋子所在位置的一列,斜方向和反斜方向没有棋子。怎么判断呢,我们引入bool类型的row[]数 阅读全文
posted @ 2020-04-11 16:45 liyexin 阅读(563) 评论(1) 推荐(1)