摘要: 题目说明: 假設有一個背包的負重最多可達8公斤,而希望在背包中裝入負重範圍內可得之總價物品,假設是水果好了,水果的編號、單價與重量如下所示: 0 李子 4KG NT$4500 1 蘋果 5KG NT$5700 2 橘子 2KG NT$2250 3 草莓 1KG NT$1100 4 甜瓜 6KG NT$6700 首先,是每种水果都只有一个的算法。#include #include int getMax(int fruitP[], int fruitW[], int form[][9], int fruitNum, int bagW){ int i, j; for(i = 1; i ... 阅读全文
posted @ 2014-03-06 13:47 yutoulck 阅读(917) 评论(0) 推荐(0) 编辑
摘要: 特点是:子问题出现重叠;使用空间换取时间,因此一般需要一个表作为空间使用;用于最优化的处理,并且拥有最优子结构;无后效性;操作步骤:确定状态变量;确定决策以及状态转移方程;例子:http://blog.163.com/guixl_001/blog/static/41764104200863015855721/ http://www.cnblogs.com/yutoulck/p/3584375.html理解动态规划并不是很难,难的是自己从问题推断出需要应用动态规划并且懂得应用动态规划,状态变量以及状态转移方程的处理需要一定的思考。 阅读全文
posted @ 2014-03-06 10:40 yutoulck 阅读(200) 评论(0) 推荐(0) 编辑
摘要: #include #include int geZiQuShu(int num[][4], int h, int l){ int up, left; if(h left){ return up + num[h][l]; } else{ return left + num[h][l];; }}main(){ int num[4][4] = {20, 20, 20, 4, 5, 6, 20, 8, 9, 10, 20, 12, 13, 14, 20, 20}; int result; result = geZiQuShu... 阅读全文
posted @ 2014-03-06 10:29 yutoulck 阅读(173) 评论(0) 推荐(0) 编辑
摘要: #include #include int transform(char str[]){ int i = 0; int result = 0; while(str[i] != '\0'){ result = result * 10 + str[i] - '0'; i++; } return result;}main(){ char* str = "1234"; int result; result = transform(str); printf("%d \n", result);} 阅读全文
posted @ 2014-03-06 10:02 yutoulck 阅读(135) 评论(0) 推荐(0) 编辑
摘要: #include #include find(int num[][3], int h, int l, int x){ int i, j; int isFinded = 0; i = 0; j = l - 1; while(i = 0){ if(num[i][j] == x){ isFinded = 1; break; } else if(num[i][j] < x) i++; else j--; } if(isFinded == 1) printf("%... 阅读全文
posted @ 2014-03-06 09:58 yutoulck 阅读(180) 评论(0) 推荐(0) 编辑