
DP
躺平平的弱鸡
IT界资深菜鸟。。
展开
-
NYOJ矩形嵌套
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=16DAG上的动态规划代码:#include #include #include using namespace std;int e[1005][1005];int N;int n;int a[1005],b[1005];int d[1005]原创 2016-03-31 18:46:59 · 350 阅读 · 0 评论 -
uva437The Tower of Babylon(不一样的dp)
我的思路和刘汝佳老师的思路不一样:思路: 把一个立方体变成6个立方体 ,即长宽高都不一样。定义状态: d[i] 为以下标为i的木块为起点所能摞的最高的高度,记忆化搜索就可以了。代码(有点长)#include #include #include using namespace std;struct node{ int a,b,c;原创 2016-09-07 19:33:26 · 373 阅读 · 0 评论 -
Uva1025A Spy in the Metro
一道dp的题 :dp[i][j] 表示从在时刻i 处在j站台 所需要最少还要等待多少时间此时有3中决策1.等1分钟2.上开往右侧的火车(如果有的话)3.上开往左侧的火车(如果有的话)边界条件 dp[T][n] = 0; for( i = 1 to n - 1) dp[T][i] = INF;要求出 dp[0][1]原创 2016-09-06 19:37:28 · 301 阅读 · 0 评论 -
NYOJ760又见LCS
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=760思路: 如果按正常的思路,都开不下那么大的数组,并且时间是1S。 注意到题目说一个序列中的数两两不同,这样我们就可以把第一个数组出现在数字的下标都记下来,然后对照第二个数组 再生成一个下标数组,求这个生成的数组的最长单调递增子序列就可以了。代码:#inclu原创 2016-09-18 18:03:36 · 293 阅读 · 0 评论 -
uva12563劲歌劲舞
一开始竟然读错了题意,没有注意到歌曲数量优先这个条件。。。。代码:#include #include #include using namespace std;int T;int n,t;int a[100];int f[55][9005];int d[55][9005];int main(){ scanf("%d",&T); in原创 2016-09-15 15:38:52 · 279 阅读 · 0 评论 -
uva116Unidirectional TSP
思路: 从后像前递推,然后正向的打印路径。代码:#include #include using namespace std;int m,n;int mp[15][110];int f[15][110];void print_ans(int k,int l){ if(l == n) return ; for(int i = 1;原创 2016-09-13 17:20:55 · 521 阅读 · 0 评论 -
uva1347Tour
按照LRJ的思路,f[i][j] 为第一个人走到第i个点 第二个人走到第j个点(i > j) 最少还需要走多少距离。代码:#include #include #include #include using namespace std;#define inf 2e9const int maxn = 1005;struct node{ double x,y;}a原创 2016-09-13 15:12:01 · 268 阅读 · 0 评论 -
hdu1246自共轭Ferrers图
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1246参照大神的DP的思路:状态方程:f[i][j] = f[i][j - 1] + f[i - 2 * j + 1][j - 1] ,f[i][j]代表了i个方格第一行不超过j 解得的个数。代码:#include int f[500][500];const原创 2016-05-08 22:25:51 · 729 阅读 · 0 评论 -
NYOJ36最长公共子序列
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=36纯模板。。代码:#include #include #include using namespace std;char s[1005];char s1[1005];int dp[1005][1005];int main(){原创 2016-04-11 18:02:48 · 471 阅读 · 0 评论 -
NYOJ737石子合并(一)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=737区间的DP,核心部分就是三层for循环,第一层枚举区间的长度,第二层枚举起点的位置,第三层枚举最后一次合并的位置,代码:#include #include #include using namespace std;#define inf 1原创 2016-04-08 14:12:11 · 421 阅读 · 0 评论 -
hdu1257最少拦截系统
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1257太笨了我。。。#include int f[1005];int main(){ int n; while(~scanf("%d",&n)) { int m = 0; f[1] = 0; wh原创 2016-03-26 17:52:23 · 233 阅读 · 0 评论 -
hdu2602Bone Collector && POJ3624Charm Bracelet
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602非常裸的0-1背包。。代码:#include #include #include using namespace std;int t;int f[1005];int v[1005];int w[1005];int main(){原创 2016-03-25 18:47:40 · 307 阅读 · 0 评论 -
hdu2955Robberies
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955典型的0-1背包的题,只不过把思路换了一下,把所有银行的钱看作是背包容量,单个的银行的钱看作重量,用f[]数组保存的是不被抓到的概率,最后扫描一下就行了.代码:#include #include #include using namespace std;con原创 2016-03-25 18:38:55 · 337 阅读 · 0 评论 -
hdu1231最大连续子序列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231如果做题的时候没有看见K的范围,那么TLE经典代码如下: - -!#include const int Min = -1e9;int a[10005];int n;int main(){ while(~scanf("%d",&n),n) {原创 2016-03-23 21:32:43 · 251 阅读 · 0 评论 -
hdu2059龟兔赛跑
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059思路(看别人博客。。):把起点和终点也看做充电站,假设现在在第i个充电站,那么dp[i]=min(第0个充电站加满电到第i个充电站所用时间,第1个充电站加满电到第i个充电站所用时间……第i - 1个充电站加满电到第i个充电站所用时间),然后用dp[n + 1] 和兔子所用的时间比一下就原创 2016-04-04 21:18:40 · 568 阅读 · 0 评论 -
nyoj17单调递增最长子序列(N*logN)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=17比起O(n ^ 2),O(N * logN)算法采用了二分查找的方法,用一个数组f[]存储最长递增的子序列,maxlen代表它的长度。、f[]已经是有序的数组了,所以二分查找非常省时,下面举个例子,从别人博客上弄得。。。。假设存在一个序列d[1..9] =原创 2016-03-31 21:24:58 · 331 阅读 · 0 评论 -
hdu1466计算直线的交点数
这道题是从HDU课件上看到的,而且是DP的课件。推导过程来自PPT:当n = 20 时, 最大的交点数 = 1 + 2 + ... + (n - 1) = n * (n - 1) / 2 = 190很容易看出前四个答案 n = 0 0n = 1 0n = 2 0 1n = 3 0 2 3 (解释一下: 0是三条直线平行的情况,2是两条直原创 2016-11-10 18:33:03 · 367 阅读 · 0 评论