![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
码农同学
爱动漫,爱AC,立志成为攻城师!
展开
-
hdu 1231 最大连续子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1231 #include using namespace std; int a[10010]; int main() { int N; while(scanf("%d",&N)!=EOF&&N){ int i,j=0,sum=0,max=-1,s=0,e=N-1; for(i=0;原创 2012-08-07 23:19:43 · 673 阅读 · 0 评论 -
编辑距离的Ruby实现
利用动态规划算法,实现最短编辑距离的计算。 #encoding: utf-8 #author: xu jin #date: Nov 12, 2012 #EditDistance #to find the minimum cost by using EditDistance algorithm #example output: # "Please input a string: " #原创 2012-11-16 18:39:34 · 609 阅读 · 0 评论 -
最长公共子序列的Ruby实现
最长公共子序列,LCS,动态规划实现。 #encoding: utf-8 #author: xu jin, 4100213 #date: Nov 01, 2012 #Longest-Commom-Subsequence #to find a longest commom subsequence of two given character arrays by using LCS algorith原创 2012-11-09 12:18:04 · 772 阅读 · 0 评论 -
矩阵连乘的Ruby实现
动态规划解决矩阵连乘问题,随机产生矩阵序列,输出形如((A1(A2A3))(A4A5))的结果。 代码: #encoding: utf-8 =begin author: xu jin, 4100213 date: Oct 28, 2012 MatrixChain to find an optimum order by using MatrixChain algorithm example原创 2012-10-30 22:00:45 · 997 阅读 · 0 评论 -
hdu 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 01背包问题,f[j]表示背包体积为j时候的最大重量 状态转移方程:f[j]=max(f[j],f[j-v[i]]+w[i]) #include #include using namespace std; int main() { int T; //freopen("G:/原创 2012-09-12 17:40:41 · 1014 阅读 · 0 评论 -
hdu 1203 I NEED A OFFER!
http://acm.hdu.edu.cn/showproblem.php?pid=1203 简单的01背包问题,f[j]表示每个学校都落选的最小概率,状态转移方程 f[j]=min(f[j],f[j-a[i]]*(1-b[i]) #include #include #include using namespace std; int main() { int n,原创 2012-09-12 16:47:07 · 792 阅读 · 0 评论 -
hdu 2546 饭卡
http://acm.hdu.edu.cn/showproblem.php?pid=2546 01背包问题,首先拿出5元买最贵的东西,那接下来就是背包容量m-5,物品数量n-1 的01背包问题了。 状态转移方程为:f[j]=max(f[j],f[j-price[i]]+price[i]) , f[j]表示买前i件物品,预算为j时的最大花销 为了好弄,我把最贵的移到数组尾部。 #inc原创 2012-09-12 00:20:21 · 5423 阅读 · 1 评论 -
nyoj 16 矩形嵌套
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述有n个矩形,每个矩形可以用a,b来描述,表示长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d或者b<c,a<d(相当于旋转X90度)。例如(1,5)可以嵌套在(6,2)内,但不能嵌套在(3,4)中。你的任务是选出尽可能多的矩形排成一行,使得除最后一个外,每一个矩原创 2012-08-13 18:16:14 · 1919 阅读 · 2 评论 -
hdu 1003 Max Sum (最大连续子序列)
http://acm.hdu.edu.cn/showproblem.php?pid=1003 动态规划。。。。。和第1231道题不同,这道题有负数! wa了n次。。。。。悲剧 #include using namespace std; int a[100010]; int main() { int T; cin>>T; for(int c=1;c<=T;c++){ int原创 2012-08-07 23:54:59 · 786 阅读 · 0 评论 -
最优二叉查找树的Ruby实现
算法导论上的伪码改写而成,加上导论的课后练习第一题的解的构造函数。 #encoding: utf-8 =begin author: xu jin date: Nov 11, 2012 Optimal Binary Search Tree to find by using EditDistance algorithm refer to > example output: "k2 is原创 2012-11-16 18:41:32 · 922 阅读 · 0 评论