
算法入门经典第二版第九章动态规划
文章平均质量分 53
MrFox_
1.少说话, 多做事。
2.现在就是将来, 本来现实, 何必幻想!
展开
-
Uva 1025 A Spy in the Metro
//紫书上的第一道dp, 水平不够, 看了好多遍, 还是没理解精神, 说说借鉴进步之处1. 逆推, 假设能到, 看dp【0】【1】2.动态方程用的时间+站3.初始化全部,紫书初始化了一部分, 没看懂//#include#include#include#includeusing namespace std;const int INF = (1<<30) - 1;c原创 2015-06-03 08:39:40 · 343 阅读 · 0 评论 -
UVA - 12563 Jin Ge Jin Qu hao
//看完了第七章的几种暴力方法后来看看第九章的动归, 动归也做了有那么几道题了, 虽然还是不怎么会,但是真的有种感觉,如果不真的理解动态方程是写不出来的。这个题也花了我不少时间,但确实是个水题。因为先看了书上的背包,以为的凑方程。最后自己想,总算写对了。//这个题:dp[i][j]表示在前i首歌中选出时间小于j的几首歌。首先,dp[i-1][j]是否就是dp[i][j]的解了,也就原创 2015-07-29 16:54:40 · 476 阅读 · 0 评论 -
UVA - 10003 Cutting Sticks
//比较巧妙, 不看书也写不出来应该。。#include#include#include#includeusing namespace std;const int maxn = 50 + 5;const int inf = 100000000;int v[maxn];int dp[maxn][maxn];int d(int l, int r){ if(l >= r-原创 2015-08-07 10:11:38 · 324 阅读 · 0 评论 -
UVA - 11584 Partitioning by Palindromes
DP:#include#include#include#includeusing namespace std;const int maxn = 1000 + 5;char s[maxn];int d[maxn];int solve(int a, int b){ while(a<b) { if(s[a] != s[b]) return 0;原创 2015-08-06 10:57:03 · 356 阅读 · 0 评论 -
UVA - 11400 Lighting System Design
DP:#include#include#include#includeusing namespace std;const int maxn = 1000 + 5;struct kk{ int v, k, c, l; bool operator < (const kk &p) const{ return v < p.v; }}vis[max原创 2015-07-31 08:51:25 · 291 阅读 · 0 评论 -
UVA - 12186 Another Crisis
//树形DP,新技能get!核心代码是书上的。。#include#include#include#include#includeusing namespace std;const int maxn=1e5 + 5;vector sons[maxn];int n, T;int dp(int u){ if(sons[u].empty()) return 1; i原创 2015-08-11 10:08:30 · 419 阅读 · 0 评论 -
UVA - 1347 Tour
//感觉这个要比紫书好理解见代码//#include#include#include#include#includeusing namespace std;#define INF 100000000;const int maxn = 1000 + 5;struct point{ int x, y;}vis[maxn];double D(int i, i原创 2015-07-04 11:40:38 · 431 阅读 · 0 评论 -
UVA - 116 Unidirectional TSP
//紫书刘汝佳源代码, 运用了回溯寻找最优决策//#include#include#include#include#define INF 100000000;using namespace std;const int maxn = 100 + 5;int a[maxn][maxn];int d[maxn][maxn];int next_[maxn][maxn];原创 2015-07-04 16:28:23 · 434 阅读 · 0 评论 -
Uva 437 The Tower of Babylon
//http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19214代码还是有点麻烦, 网上说还可以是将面积排序转化成一个最大上升子序列问题, 不懂不过自己想了会儿终于知道DAG是什么了, 基础知识不扎实, 拓扑不熟, 自己推得, 以后熟悉了其他的会补上进步最大的是有些题可以将物体转化成一个点, 进而成图, 方便原创 2015-06-03 13:49:56 · 443 阅读 · 0 评论 -
UVA - 10285 Longest Run on a Snowboard
//DAG 有向无环图 开始R和C弄反了 一直调也不出结果 査代码还是直接输出dp数组比较直观//#include#include#include#include#includeusing namespace std;#define INF (1<<30)const int maxn = 100 + 5;int vis[maxn][maxn];int dp[maxn]原创 2015-06-09 12:42:43 · 439 阅读 · 0 评论 -
UVA 10118 Free Candies
//开始以为是个数塔。。。//记忆化搜索:dp[a][b][c][d]的意义是第一堆选了a, 第二堆选了b个, 。。。。。之后剩下的最大值;#include#include#include#include#includeusing namespace std;const int maxn = 40 + 5;int vis[maxn][4];int dp[maxn][maxn原创 2015-09-21 19:34:01 · 471 阅读 · 0 评论