码迷,mamicode.com
首页 > 其他好文 > 详细

状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

时间:2015-10-28 21:01:53      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

题意:采蘑菇。现在采了n座山,共5座山,最后要求有三个篮子的蘑菇量是1024的整数倍,丢掉后一直减1024直到不超过1024

分析:n <= 3时直接1024,否则状压枚举哪三个篮子丢弃,更新最值

 

/************************************************
* Author        :Running_Time
* Created Time  :2015/10/28 星期三 19:21:49
* File Name     :C.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos (-1.0);

int main(void)    {
    int n;
    int a[5];
    while (scanf ("%d", &n) == 1)   {
        memset (a, -1, sizeof (a));
        int ans = 0;
        for (int i=0; i<n; ++i) scanf ("%d", &a[i]);
        if (n <= 3) {
            ans = 1024;
        }
        else    {
            int S = 1 << 5;
            for (int i=0; i<S; ++i) {
                int num = __builtin_popcount (i);
                if (num != 3)   continue;
                int x = 0, y = 0, sum = 0, sum2 = 0;
                for (int j=0; j<5; ++j) {
                    if (i & (1 << j))   {
                        if (a[j] == -1)  x++;
                        else sum += a[j];
                    }
                    else    {
                        if (a[j] == -1)  y++;
                        else    sum2 += a[j];
                    }
                }
                if (!x && sum % 1024 != 0) continue;
                if (y)  ans = max (ans, 1024);
                else    {
                    ans = max (ans, (sum2 - 1) % 1024 + 1);
                }
            }
        }
        printf ("%d\n", ans);
    }

    //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    return 0;
}

  

状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/4918460.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!