上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 14 下一页

2012年11月2日

01背包问题,动态规划求解

摘要: 01背包问题:1.递归思想0- 1 背包问题如果采用递归算法来描述则非常清楚明白, 它的算法根本思想是假设用布尔函数knap( s, n) 表示n 件物品放入可容质量为s 的背包中是否有解( 当knap 函数的值为真时说明问题有解,其值为假时无解) . 我们可以通过输入s 和n 的值, 根据它们的值可分为以下几种情况讨论:( 1) 当s= 0时可知问题有解, 即函数knap( s, n) 的值为true; ( 2) 当s< 0 时这时不可能,所以函数值为false; ( 3) 当输入的s> 0 且n< 1 时即总物品的件数不足1, 这时函数值为false,只有s> 0 阅读全文

posted @ 2012-11-02 16:30 为梦飞翔 阅读(8363) 评论(0) 推荐(0)

2012年11月1日

最长递增子串

摘要: View Code #include<IOSTREAM.H>#include <IOMANIP.H>#include <STRING.H>#include <STDLIB.H>//动态规划:需要一个数组b[n],其中b[i]是以x[i]结尾最长子串的长度,而b[i+1]=max(b[k]&&x[i+1]>x[k]}+1void main(){ char array[]="abcdgdfgdggefrte"; int *p=(int*)malloc(strlen(array)*sizeof(int)); p 阅读全文

posted @ 2012-11-01 13:48 为梦飞翔 阅读(306) 评论(0) 推荐(0)

2012年10月31日

求两个字符串的相似度或子串

摘要: View Code #include<IOSTREAM.H>#include <IOMANIP.H>#include <STRING.H>#include <STDLIB.H>//求两个字符串的最大公共子串//公共子串是指两个串中存在相同顺序的字符,但这些字符不必相邻/*int Length(int *array,char * A,int m,char *B,int n){ if (array[(strlen(B)+1)*m+n]<strlen(B)) return array[(strlen(B)+1)*m+n]; int temp; i 阅读全文

posted @ 2012-10-31 21:59 为梦飞翔 阅读(337) 评论(0) 推荐(0)

动态规划

摘要: 1装配线调度:一个汽车公司有两套装配线,每条装备线各有6个装配站,每个装配站完成装配需要一定的时间,两条装配线对应的站完成相同的功能,但所用的时间不一定相等。现在希望找出完成装配用的最少的装配站点。分析:经过第1条线的第N个装配站的最短的路径可能是从第一条线的第N-1个装配站送过去的,也可能由第二条线的第N-1个装配站送过去的,不管是从哪条线的第N-1个站送过来的,这个路径一定是经过该N-1站的最短路径,如果不是,那么就会有更短的路径从N-1站到达N装配站View Code #include<IOSTREAM.H>typedef struct Point{ int x;int y; 阅读全文

posted @ 2012-10-31 10:30 为梦飞翔 阅读(235) 评论(0) 推荐(0)

2012年10月29日

求和最大子串

摘要: #include<iostream.h>typedef struct Element{ int index; int sum;}Element;void main(){ int array[]={-33,16,-48,5,16,-2,3,-11,10,-1}; Element elem; elem.index=0; elem.sum=array[0]; int temp=array[0]; for(int i=1;i<sizeof(array)/sizeof(int);i++) { if(temp<0) temp=0; ... 阅读全文

posted @ 2012-10-29 19:36 为梦飞翔 阅读(202) 评论(0) 推荐(0)

2012年10月26日

二叉排序树的相关操作

摘要: #include <IOSTREAM.H>#include <STDLIB.H>//二叉树的生成和释放typedef struct Node{ int data; struct Node * pParent; struct Node * pLeftChild; struct Node * pRightChild;}Node;Node * Create_BTree(int *array,Node* pParent=NULL)//二叉排序树的创建,按照先序遍历的方法进行构造{ static int i=0; if (array[i]==0) { ... 阅读全文

posted @ 2012-10-26 17:04 为梦飞翔 阅读(934) 评论(0) 推荐(0)

2012年10月23日

统计一个字符串中各个英文单词的出现的频数

摘要: #include<iostream.h>#include<string.h>#include<stdlib.h>void main(){ char destr[]=" hello hello sfs che heloo dsljd hello hello "; int num=1; char *p=destr; while(*p!='\0') { if(*p>='A'&&*p<='Z') { *p=*p-'A'+'a'; } if( 阅读全文

posted @ 2012-10-23 23:31 为梦飞翔 阅读(3423) 评论(0) 推荐(0)

2012年10月17日

计数排序

摘要: #include <IOSTREAM.H>//计数排序,这是基数排序的基本操作//待排序的数字在某一范围内,如从0到9void main(){ int a[10]={0}; int array[]={2,3,4,2,3,5,2,9,8,6,5,0,1,7,6,8,9,5,3,6,7}; int temp[21]; for (int i=0;i<21;i++) { a[array[i]]++; } a[0]--; for(i=1;i<10;i++) a[i]+=a[i-1]; for (i=0;i<21;i++) ... 阅读全文

posted @ 2012-10-17 15:05 为梦飞翔 阅读(230) 评论(0) 推荐(0)

2012年10月16日

快速排序

摘要: #include<iostream.h>//快速排序//起核心算法是划分子序列int Partition(int *a,int p,int r){ int x=a[p]; int i=p,j=r; while(true) { while(a[j]>x) j--; while(a[i]<x) i++; if(i<j) { if(a[i]==a[j]) //打破重复元素 j--; else ... 阅读全文

posted @ 2012-10-16 22:56 为梦飞翔 阅读(187) 评论(0) 推荐(0)

堆排序

摘要: #include<iostream.h>//堆排序1,建堆,排序void Build_Heap(int *a,int length){ for(int i=1;i<length;i++) { int j=i; while(j-1>=0) { if(a[j]>a[(j-1)/2])//大于父节点,交换 { int temp=a[j];a[j]=a[(j-1)/2];a[(j-1)/2]=temp; j=(j-1)/2; ... 阅读全文

posted @ 2012-10-16 10:34 为梦飞翔 阅读(179) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 14 下一页

导航