Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么wa?全排列然后每个排列进行模拟。 #include <stdio.h> #include <stdlib.h> int best=0; int limit; struct node{ int w; int v; }nodes[10]; void swap(node *s1, node *s2) { node temp = *s1; *s1 = *s2; *s2 = temp; } void arrange(node *s, int k, int m) { int i; if (k == m) { int aweigth=0,acost=0; int bweigth=0,bcost=0; int flog; for(i=0;i<=m;i++) { if(i==0) { aweigth+=s[0].w; acost+=s[0].v; flog=1; } else { if(abs(aweigth-bweigth)>limit) { if(flog==1) { bweigth+=s[i].w; bcost+=s[i].v; flog=2; } else { aweigth+=s[i].w; acost+=s[i].v; flog=1; } } else { if(flog==2) { bweigth+=s[i].w; bcost+=s[i].v; } else { aweigth+=s[i].w; acost+=s[i].v; } } } } if(best<bcost) best=bcost; } else { for (i = k; i <= m; i++) { swap(&s[k], &s[i]); arrange(s, k + 1, m); swap(&s[k], &s[i]); } } } int main() { int n; int i; scanf("%d%d", &n,&limit); for (i = 0; i < n; i++) scanf("%d%d", &nodes[i].w,&nodes[i].v); arrange(nodes, 0, n-1); printf("%d\n",best); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator