
dp
久许
朋友拍了拍我,说我可不是什么幺蛾子
展开
-
dp 从一个数组中选取若干项,求最大和(项与项之间不相邻)
#include<cstdio>#include<algorithm>using namespace std;#define n 7int arr[n] = {1,2,4,1,7,8,3};int dis_sum[100];void dp(){ dis_sum[0] = arr[0]; dis_sum[1] = max(arr[0],arr[1]);...原创 2019-03-23 10:32:57 · 975 阅读 · 0 评论 -
dp 最大连续子序列和
#include<cstdio>#include<algorithm>using namespace std;#define n 8int arr[n] = { 1, -2, 4, 1, -5, 7, -8, 3 };int near_s[100];void dp() { near_s[0] = arr[0]; for (int i = 1; i &...原创 2019-03-23 11:02:26 · 225 阅读 · 0 评论 -
动态规划,判断一个数列的若干项之和是否等于某一个给定的数
#include<cstdio>using namespace std;#define n 6int arr[6] = { 3, 34, 4, 12, 5, 2 };int subset[6][100];void dp(int C) { //C是要凑的数 for (int i = 0; i < n; i++) subset[i][0] = 1; //不管对...原创 2019-03-23 09:51:17 · 978 阅读 · 0 评论 -
01背包
#include<cstdio>#include<algorithm>using namespace std;#define C 10 //背包的呃容量#define n 5 //物品的个数int w[n] = { 2, 2, 6, 5, 4 }; //物品的重量int v[n] = { 6, 3, 5, 4, 6 }; //物品的价值int x[n]...原创 2019-03-22 19:50:16 · 126 阅读 · 0 评论