zoukankan      html  css  js  c++  java
  • 状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)

    题目传送门

    题意:采蘑菇。现在采了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
    ", ans);
        }
    
        //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.
    ";
    
        return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    强化学习 相关资源
    Log4j输出文件到目的地
    httpclient 封装post 和get
    Cookie 和Session区别
    day09 request 和response
    Jmeter 断言
    Jmeter自学笔记10----性能测试基础实战
    Jmeter 目录
    性能测试解惑之并发压力
    设计模式,就是那个抽象工厂没写
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4918460.html
Copyright © 2011-2022 走看看