php网站建设流程,flash 网站带后台,网站运营方案案例,天津网站建设定制http://acm.uestc.edu.cn/problem.php?pid1489cid164 其实就是用搜索做0/1背包 不要被Fibonacci 唬住了#xff0c;没什么用。#xff0c;。。。。。这个比较坑爹 剪枝在代码中说明了 ?View Code C 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2… http://acm.uestc.edu.cn/problem.php?pid1489cid164 其实就是用搜索做0/1背包 不要被Fibonacci 唬住了没什么用。。。。。。这个比较坑爹 剪枝在代码中说明了 ?View Code C 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86#include StdAfx.h
#include iostream
#include stdio.h
#include memory.h
#include string
#include queue
#include math.h
#includecstdlib
#includealgorithm
using namespace std;
#define LL long long
LL n,w,maxx;
LL f[60],ww[60];
LL m[51][51];
struct node
{LL c,w;
};
node a[60];
bool cmp(node a,node b)
{if (a.w!b.w) return a.wb.w;else return a.cb.c;
}void find(int i,LL w,LL c,int flag)
{ if (cmaxx) maxxc;if (in) return ;//后面全选都没用if (f[n-1]-f[i]a[i].ccmaxx) return;//后面全选都不会超重if (f[n-1]-f[i]a[i].ccmaxx ww[n-1]-ww[i]a[i].ww){maxxf[n-1]-f[i]a[i].cc;return ;}if (flag0 a[i].wa[i-1].w) //上一个和a[i]等重而且价值更高的都没选肯定不会选a[i]{//不选find(i1,w,c,0);return ;}else{//不选find(i1,w,c,0);//选if (wa[i].w) return ; //超重了find(i1,w-a[i].w,ca[i].c,1); }}int main()
{int t;cint;for (int tt0;ttt;tt){cinnw;memset(a,0,sizeof(a));memset(m,0,sizeof(m));memset(f,0,sizeof(f));memset(ww,0,sizeof(ww));for (int i0;in;i){cina[i].wa[i].c;}maxx0;sort(a,an,cmp);f[0]a[0].c;ww[0]a[0].w;for (int i1;in;i){f[i]f[i-1]a[i].c;ww[i]ww[i-1]a[i].w;}find(0,w,0,1);coutCase tt1: maxxendl;}return 0;
} 转载于:https://blog.51cto.com/darkscope/989019