• BZOJ1334 [Baltic2008]Elect


    直接DP一下就好了嘛、、、

    首先对人数从大到小排序,然后f[i]表示的是人数为i的政党联盟能否成立

    f[i] 由 f[i - a[now]]转移过来,同时保证i - a[now] <= sum即可

     1 /**************************************************************
     2     Problem: 1334
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:156 ms
     7     Memory:1196 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11 #include <algorithm>
    12  
    13 using namespace std;
    14  
    15 int n, sum, ans;
    16 int a[305];
    17 int f[100005];
    18  
    19 int main() {
    20     int i, j;
    21     scanf("%d", &n);
    22     for (i = 1; i <= n; ++i)
    23         scanf("%d", a + i), sum += a[i];
    24     sort(a + 1, a + n + 1);
    25     f[0] = 1;
    26     for (i = n; i; --i)
    27         for (j = sum / 2 + a[i]; j >= a[i]; --j)
    28             if (f[j - a[i]])
    29                 f[j] = 1, ans = max(j, ans);
    30     printf("%d
    ", ans);
    31     return 0;
    32 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    bzoj1415 NOI2005聪聪和可可
    Tyvj1952 Easy
    poj2096 Collecting Bugs
    COGS 1489玩纸牌
    COGS1487 麻球繁衍
    cf 261B.Maxim and Restaurant
    cf 223B.Two Strings
    cf 609E.Minimum spanning tree for each edge
    cf 187B.AlgoRace
    cf 760B.Frodo and pillows
  • 原文地址:https://www.cnblogs.com/rausen/p/4168196.html
Copyright © 2020-2023  润新知