
动态规划DP
怎呼虹
你只负责精彩,命运自有安排。
展开
-
HDU 1176 免费馅饼 动态规划 数塔变形
HDU 1176 免费馅饼简要分析: 1、空间换时间。边缘数组多开,不用进行首尾的特殊处理。 2、0 不影响结果代码如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f原创 2016-12-16 14:36:15 · 325 阅读 · 0 评论 -
HDU 1203 I NEED A OFFER 概率DP
传送门:HDU 1203 I NEED A OFFER 分析: 这是一道概率DP的题目。注意: 1、要初始化成1.0 2、用补集求概率 3、DP的过程中,概率要相乘而不是相加或者相减代码如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using原创 2016-12-22 11:41:39 · 296 阅读 · 0 评论 -
HDU 1421 搬寝室 二维DP
传送门:HDU 1421 搬寝室分析: 先对n中物品的重量排序 令dp[i][j]表示前i个物品中选j对的最小疲劳度。 则dp[i][j]可能含有第i个物品(这种情况下,第i种物品一定是和第i-1个物品配对), 则dp[i][j]=dp[i-2][j-1]+(val[i]-val[i-1])*(val[i]-val[i-1]) dp[i][j]的j对也可能不含有第i个物品,此时有 dp[原创 2016-12-25 01:02:30 · 387 阅读 · 0 评论 -
HDU 1160 FatMouse's Speed DP 路径回溯
传送门:HDU 1160 FatMouse’s Speed 吐槽分析: 最长递增递减子序列(动态规划) index从1开始 ms()只要到 m+i就可以了 不要到 m+i+1 坑爹啊AC代码如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using原创 2016-12-19 01:14:13 · 450 阅读 · 0 评论 -
HDU 1789 Doing Homework again 贪心 DP
传送门:HDU 1789 Doing Homework again分析: 这里默认作业的期限 也不会超过1000 所以我们vis数组也就是开的1010 果不其然 数据并没有超过100的贪心策略:排序预处理 + 期限尽量从后面开始考虑。代码如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#inc原创 2016-12-26 12:02:21 · 594 阅读 · 0 评论 -
HDU 1978 How many ways DP路径
传送门:HDU 1978 How many ways分析: 路径数目DP。 dp[x][y]代表x,y到终点的方案数代码如下:#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define INF 0x3f3f3f原创 2016-12-27 00:16:16 · 409 阅读 · 0 评论 -
HDU 1159 Common Subsequence 公共子序列 简单DP
传送门:HDU 1159 Common Subsequence分析见注释,入门DP。很经典。#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define ms(x, y)原创 2016-12-18 00:07:45 · 533 阅读 · 0 评论 -
HDU 1260 Tickets 简单DP
传送门:HDU 1260 Tickets分析: 一道简单的DP题,代码思路简单清晰。注意时间转化。不然WA。代码如下;#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#d原创 2016-12-20 23:54:58 · 574 阅读 · 0 评论 -
POJ 1837 Balance DP 二维背包
传送门:POJ 1837 Balance分析: g个挂钩挂上的极限值:15*25*20==7500。 那么在有负数的情况下是-7500~~7500 此时的平衡点为0。 我们当然可以将平衡点往右移7500个单位,范围就变成了 0~~15000。(正化方便处理,这样平衡点就是7500)代码如下:#include <stdio.h>#include <string.h>int dp[21][1原创 2017-02-10 14:43:18 · 436 阅读 · 0 评论