状态压缩 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\n", ans);
} //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0;
}

  

上一篇:anyRTC 联合 vInClass 打造在线教育上课模式


下一篇:weex 启动 android 模拟器(mac环境)