HDU 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】 收藏
Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955
最大报销额 http://acm.hdu.edu.cn/showproblem.php?pid=1864
最大连续子序列 http://acm.hdu.edu.cn/showproblem.php?pid=1231
max sum http://acm.hdu.edu.cn/showproblem.php?pid=1003
Largest Rectangle http://acm.hdu.edu.cn/showproblem.php?pid=1506
City Game http://acm.hdu.edu.cn/showproblem.php?pid=1505
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602
Super Jumping http://acm.hdu.edu.cn/showproblem.php?pid=1087
命运http://acm.hdu.edu.cn/showproblem.php?pid=2571
Monkey And Banana
Big Event in HDU http://acm.hdu.edu.cn/showproblem.php?pid=1171
数塔http://acm.hdu.edu.cn/showproblem.php?pid=2084
免费馅饼http://acm.hdu.edu.cn/showproblem.php?pid=1176
I Need A Offer http://acm.hdu.edu.cn/showproblem.php?pid=1203
FATE http://acm.hdu.edu.cn/showproblem.php?pid=2159
How To Type http://acm.hdu.edu.cn/showproblem.php?pid=2577
Coins http://acm.hdu.edu.cn/showproblem.php?pid=2844
Beans http://acm.hdu.edu.cn/showproblem.php?pid=2845
Largest Submatrix http://acm.hdu.edu.cn/showproblem.php?pid=2870
Matrix Swapping II http://acm.hdu.edu.cn/showproblem.php?pid=2830
最大完全子矩阵,以第i行为底,可以构成的最大矩阵,因为该题可以任意移动列,所以只要大于等于height[i]的都可以移动到一起,求出 height>=height[i]的个数即可,这里用hash+滚动,先求出height[i]出现的次数,然后逆序扫一遍 hash[i]+=hash[i+1];
最少拦截系统http://acm.hdu.edu.cn/showproblem.php?pid=1257
Common Subsequence http://acm.hdu.edu.cn/showproblem.php?pid=1159
★ 搬寝室http://acm.hdu.edu.cn/showproblem.php?pid=1421
★ Humble Numbers http://acm.hdu.edu.cn/showproblem.php?pid=1058
★ Doing Homework Again http://acm.hdu.edu.cn/showproblem.php?pid=1789
How Many Ways http://acm.hdu.edu.cn/showproblem.php?pid=1978
珍惜现在 感恩生活http://acm.hdu.edu.cn/showproblem.php?pid=2191
Piggy-Bank http://acm.hdu.edu.cn/showproblem.php?pid=1114
★ Max Sum Plus Plus http://acm.hdu.edu.cn/showproblem.php?pid=1024
当n>m时, Sum[m][n]=max{Sum[m-1][k],Sum[m][n-1]}+v[n]; 其中,m-1<=k<j,解释为,v[n]要么加在Sum[m][n-1],段数不变,要么独立成段接在前n-1个数取m-1段所能构成的最大值后面
2. 空间的优化:
FatMouse’s Speed http://acm.hdu.edu.cn/showproblem.php?pid=1160
Cstructing Roads http://acm.hdu.edu.cn/showproblem.php?pid=1025
用一个数组记录dp[]记录最长的子序列,len表示长度,如果a[i]>dp[len], 则接在后面,len++; 否则在dp[]中找到最大的j,满足dp[j]<a[i],把a[i]接在dp[j]后面;
FatMouse Chees http://acm.hdu.edu.cn/showproblem.php?pid=1078
To the Max http://acm.hdu.edu.cn/showproblem.php?pid=1081
龟兔赛跑http://acm.hdu.edu.cn/showproblem.php?pid=2059
if(val[i] - val[j]<=C){
★ Employment Planning http://acm.hdu.edu.cn/showproblem.php?pid=1158
Dividing http://acm.hdu.edu.cn/showproblem.php?pid=1059
Human Gene Factions http://acm.hdu.edu.cn/showproblem.php?pid=1080
状态转移方程:
f[i][j]=Max(f[i-1][j-1]+r[a[i]][b[j]], f[i][j-1]+r[‘-‘][b[j]],f[i-1][j]+r[a[i]][‘-‘]);
★ Doing Homework http://acm.hdu.edu.cn/showproblem.php?pid=1074
具体实现为: 对每种状态遍历n项任务,如果第i项没有完成,则计算出Dp[next]的最优解
Free DIY Tour http://acm.hdu.edu.cn/showproblem.php?pid=1224
重温世界杯http://acm.hdu.edu.cn/showproblem.php?pid=1422
这题的状态不难理解,状态表示为,如果上一个城市剩下的钱不为负,也就是没有被赶回杭电,则再考虑它对下一个城市的影响;如果上一个城市剩下的前加上当前城市的前大于当前城市的生活费,那么Dp[i]=Dp[i-1]+1;
值得注意的而是这题的数据为100000;不可能以每个城市为起点来一次Dp,时间复杂度为n^2;足已超时;
我是这样处理的,在保存的数据后面再接上1…n的数据,这样扫描一遍的复杂度为n;再加一个优化, 当Dp[i]==n时,也就是能全部游完所有城市的时候,直接break;
Pearls http://acm.hdu.edu.cn/showproblem.php?pid=1300
Zipper http://acm.hdu.edu.cn/showproblem.php?pid=1501
★Fast Food http://acm.hdu.edu.cn/showproblem.php?pid=1227
Warcraft http://acm.hdu.edu.cn/showproblem.php?pid=3008
Regular Words http://acm.hdu.edu.cn/showproblem.php?pid=1502
Advanced Fruits http://acm.hdu.edu.cn/showproblem.php?pid=1503