状态压缩 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;
}
状态压缩 UVALive 6068 The Little Girl who Picks Mushrooms (12长春C)的更多相关文章
- UVALive 3956 Key Task (bfs+状态压缩)
Key Task 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/D Description The Czech Technica ...
- UVALive 3953 Strange Billboard (状态压缩+枚举)
Strange Billboard 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/A Description The marke ...
- UVALive 2520 Holedox Moving(BFS+状态压缩)
这个题目在比赛的时候我们是没有做出来的,但是听到他们说进制哈希的时候,感觉真的是挺高端的,于是赛后开始补题,本着我的习惯在看题解之前自己再试着写一遍,我当时存储状态的方法是string + map,我 ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- NOIP2005过河[DP 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
随机推荐
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- js判断元素是否隐藏的方法
代码如下: JavaScript代码如下: if( document.getElementById("div").css("display")==='none' ...
- TokuDB的特点验证 - billy鹏
TokuDB的特点验证 - billy鹏 时间 2014-03-03 14:28:00 博客园_billy鹏的足迹原文 http://www.cnblogs.com/billyxp/p/35674 ...
- mysql将int 时间类型格式化
摘要 DATE_FORMAT(date,format) 根据format字符串安排date值的格式. DATE_FORMAT(date,format) 根据format字符串安排date值的格式. ...
- Ninject学习笔记<一>
本文转载自永远的阿哲 如果给您带来不便请联系博主. Ninject是一款.Net平台下的开源依赖注入框架.按照官方说法,它快如闪电.超级轻量,且充分利用了.Net的最新语法,使用Lambda表达式代替 ...
- 3Sum Closest & 3Sum Smaller
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- python在线文档
中文 http://python.usyiyi.cn/--------------------------不完整 http://www.pythondoc.com/pythontutorial27/i ...
- css样式,层叠顺序属性z-index
在做项目的时候,居然单击后显示的顺序一直被别的li标签压着,最后终于找到了,是css的z-index属性赋值了,值越大,显示的层就越高 详情推荐百度百科:z-index z-index是针对网页显示中 ...
- HDU1130 卡特兰数
How Many Trees? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Redis适用于高并发的递增、递减功能
递增指令:incr(默认从0开始) 递减指令:decr(默认从0开始,递减会出现负数,这点跟memcache不一样,mc到0) 如下: 附上shardedJedisPool和JedisCluster的 ...