bzoj1334 [Baltic2008]elect

Source: Internet
Author: User

The Descriptionn political party will form a joint cabinet, each party has its own number of seats. Now I want you to find a way to choose a party that has more seats than half of the total, and the more seats the Union cabinet has, the better. For a joint cabinet, if a party withdraws, the other party is still more than half the total number of seats, the party is called superfluous, which is not allowed. The first line of Input gives the number of political parties. Its value is less than or equal to 300 the seats for each party are given below. Total number of seats less than or equal to 100000Output the maximum number of seats in your cabinet scheme. Sample Input4
1 3 2 4
Sample Output7HINT

Choose a second party and a fourth

I began to brush up the water problem ... Press A[i] from the big to the small sort, then the backpack DP a political party after the exit of the seat is equal to half of the total, is to be transferred from the J<=S/2 F[j]
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < algorithm> #include <cmath> #include <queue> #include <deque> #include <set> #include <map > #include <ctime> #define LL long long#define INF 0x7ffffff#define pa pair<int,int> #define Pi    3.1415926535897932384626433832795028841971using namespace Std;inline ll read () {ll x=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline void Write (LL a) {if (a<0) {printf ("-"); a=-a;} if (a>=10) write (A/10);p Utchar (a%10+ ' 0 ');} inline void Writeln (LL a) {write (a);p rintf ("\ n");} int N,s;int A[500];bool F[100010];int main () {n=read (); for (int i=1;i<=n;i++) A[i]=read (), S+=a[i];sort (A+1,a+n+1, Greater<int> ()); f[0]=1;for (int i=1;i<=n;i++) {for (int j=100000;j>=a[i];j--) if (J-A[I]&LT;=S/2) {f[j]=f[ J]|f[j-a[i]];}} for (int i=100000;i>=0;i--) {if (F[i]) {printf ("%d\n", I);  return 0; }  }}

bzoj1334 [Baltic2008]elect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.