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..都提交了4~5次了(具体几次不记得了)..什么都试过了..唉……所有见得到想得到的数据都过了……但是…… 附上源码吧…… #include <iostream> #include <cstdlib> #include <string> #include <bitset> using namespace std; const int candidate_count_max = 200; const int jury_count_max = 20; const int preference_max = 20 * jury_count_max; const int preference_min = -20 * jury_count_max; const int preference_count_max = preference_max-preference_min+1; const int preference_excursion = -preference_min; typedef bitset<candidate_count_max+1> name_t; int v[candidate_count_max+1]; int s[candidate_count_max+1]; int l[candidate_count_max+1]; int r[candidate_count_max+1]; int _f[jury_count_max+1][preference_count_max+1]; name_t _a[jury_count_max+1][preference_count_max+1]; int candidate_count = 0; int jury_count = 0; inline int &f(int i, int j) { return _f[i][j+preference_excursion]; } inline name_t &a(int i, int j) { return _a[i][j+preference_excursion]; } inline void reset(void) { for (int i = 0; i <= jury_count; ++i) for (int j = preference_min; j <= preference_max; ++j) { f(i, j) = -1; a(i, j) = 0; } f(0, 0) = 0; } inline name_t dynamic(void) { for (int i = 1; i <= jury_count; ++i) for (int j = 1; j <= candidate_count; ++j) { int s = preference_min; int t = preference_max; if (v[j] > 0) t = preference_max - v[j]; else s = preference_min - v[j]; for (int k = s; k <= t; ++k) { if (f(i-1, k-v[j]) < 0) continue; if (a(i-1, k-v[j]).test(j)) continue; if (f(i-1, k-v[j]) + ::s[j] <= f(i, k)) continue; f(i, k) = f(i-1, k-v[j]) + ::s[j]; a(i, k) = a(i-1, k-v[j]); a(i, k).set(j); } } for (int i = 0; i <= preference_max; ++i) { if (f(jury_count, i) >= 0) { if (f(jury_count, i) > f(jury_count, -i)) return a(jury_count, i); else return a(jury_count, -i); } else if (f(jury_count, -i) >= 0) return a(jury_count, -i); } return a(0, 0); } int main(int argc, char *argv[]) { cin >> candidate_count >> jury_count; reset(); int x, y, c = 0; while (candidate_count != 0 && jury_count != 0) { for (int i = 1; i <= candidate_count; ++i) { cin >> l[i] >> r[i]; v[i] = l[i] - r[i]; s[i] = l[i] + r[i]; } name_t list; list = dynamic(); x = y = 0; for (int i = 1; i <= candidate_count; ++i) if (list[i]) { x += l[i]; y += r[i]; } cout << "Jury #" << ++c << endl; cout << "Best jury has value " << x; cout << " for prosecution and value " << y; cout << " for defence:" << endl; for (int i = 1; i <= candidate_count; ++i) if (list[i]) cout << ' ' << i; cout << endl << endl; cin >> candidate_count >> jury_count; reset(); } return EXIT_SUCCESS; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator