状态压缩 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 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
随机推荐
- js打印(控件)及多种方式
非常好用的LODOP打印控件 Lodop打印控件简单使用方法 1.安装. 2.调用LodopFuncs.js文件. 3.增加OBJECT对象 <script language="jav ...
- lucene搜索方式(query类型)
Lucene有多种搜索方式,可以根据需要选择不同的方式. 1.词条搜索(单个关键字查找) 主要对象是TermQuery 调用方式如下: Term term=new Term(字段名,搜索关键字);Qu ...
- ref游标(动态游标)
参照变量--用于存放数值指针的变量 游标变量(ref cursor) 使用游标时,当定义游标时不需要指定相应的select语句,但是当使用 游标时(open时)需要指定select语句 ...
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- 一步步实现Nagios监控linux主机及飞信报警
一步步实现Nagios监控linux主机及飞信报警 上篇文章介绍了在linux主机上架设nagios监控服务,并对windows主机进行服务状态变化的监控,这次我们继续上次内容. 首先实现n ...
- 一段功能齐全的PHP常用重定向代码html+js+header
/** * 重定向浏览器到指定的 URL * * @param string $url 要重定向的 url * @param int $delay 等待多少秒以后跳转 * @param bool $j ...
- wireshark http抓包命令行详解
This article is a quick and easy HowTo detailing the use of Wireshark or another network sniffing pr ...
- 《ASP.NET1200例》统计网站访问量源代码
void Application_Start(object sender, EventArgs e) { //在应用程序启动时运行的代码 int count=0; ...
- 12.从上往下遍历二元树[LevelOrderOfBinaryTree]
[题目] 输入一颗二元树,从上往下按层打印树的每个结点,同一层中按照从左往右的顺序打印. 例如输入 8 / \ 6 10 /\ /\ 5 7 9 11 输出8 ...
- LightOJ 1234 Harmonic Number (打表)
Harmonic Number Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submi ...