DFS水题 URAL 1152 False Mirrors
/*
题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击
搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝吧
回溯写挫了,程序死循环,跑不出来。等回溯原理搞清楚了,下次自己重写一遍:)
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
bool vis[MAXN];
int n, ans; void DFS(int sum, int tot)
{
if (tot >= ans) return ;
if (sum == ) {ans = min (ans, tot); return ;} for (int i=; i<=n; ++i)
{
if (!vis[i])
{
vis[i] = true;
int s1 = (i == ) ? n : i - ;
int s2 = (i == n) ? : i + ;
if (vis[s1]) s1 = ;
if (vis[s2]) s2 = ;
vis[s1] = true; vis[s2] = true;
sum -= a[s1]; sum -= a[s2]; sum -= a[i]; tot += sum;
DFS (sum, tot);
tot -= sum; sum += a[s1]; sum += a[s2]; sum += a[i];
vis[s1] = false; vis[s2] = false; vis[i] = false;
}
}
} int main(void) //URAL 1152 False Mirrors
{
//freopen ("N.in", "r", stdin); while (scanf ("%d", &n) == )
{
int sum = ; a[] = ;
for (int i=; i<=n; ++i) {scanf ("%d", &a[i]); sum += a[i];}
memset (vis, false, sizeof (vis)); ans = INF; DFS (sum, );
printf ("%d\n", ans);
} return ;
}
DFS水题 URAL 1152 False Mirrors的更多相关文章
- ural 1152. False Mirrors
1152. False Mirrors Time limit: 2.0 secondMemory limit: 64 MB Background We wandered in the labyrint ...
- Ural 1152 False Mirrors(状压DP)
题目地址:space=1&num=1152">Ural 1152 初学状压DP,原来状压仅仅是用到了个位运算.. 非常水的状压DP.注意四则运算的优先级是高于位运算的..也就是 ...
- URAL 1152. False Mirrors (记忆化搜索 状压DP)
题目链接 题意 : 每一颗子弹破坏了三个邻近的阳台.(第N个阳台是与第1个相邻)射击后后的生存的怪物都对主角造成伤害- 如此,直到所有的怪物被消灭,求怎样射击才能受到最少伤害. 思路 : 状压,数据不 ...
- URAL 1152. False Mirrors(DP)
题目链接 理解了题意之后,就不难了..状态压缩+暴力. #include <cstring> #include <cstdio> #include <string> ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- 【wikioi】1229 数字游戏(dfs+水题)
http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...
- 咸鱼的ACM之路:DFS水题集
DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...
- Tree Requests CodeForces - 570D (dfs水题)
大意: 给定树, 每个节点有一个字母, 每次询问子树$x$内, 所有深度为$h$的结点是否能重排后构成回文. 直接暴力对每个高度建一棵线段树, 查询的时候相当于求子树内异或和, 复杂度$O((n+m) ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
随机推荐
- SpringCloud遇到的坑
1. 今天使用Feign 调用其他项目,结果一直跳转到断路器,跟踪发现是接口响应时间较长,解决方案 解决:# 在 Feign 模块中,单独设置这个超时时间不行,还要额外设置 Ribbon 的超时时间, ...
- using the flume-ng-sql-source plugin to push data from Mysql DB to Spark
org.apache.flume.EventDeliveryException while running flume and sending data to spark · Issue #21 · ...
- HTML——使用表格进行页面布局
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- safi 中placeholder不垂直居中
用css hack将line-height 设置为1 例子: input{height: 32px; line-height: 32px; [;line-height: 1px;]};
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- 安卓AndroidManifest.xml介绍
先说一下,我的开发环境为Eclipse 3.7.1 + Android SDK + Android 1.5(API level3) Android最大的一个特点,就是用xml文件来配置,这个演习了Ja ...
- Linux 高精度定时器hrtimer 使用示例【转】
本文转载自:http://blog.csdn.net/dean_gdp/article/details/25481225 hrtimer的基本操作 Linux的传统定时器通过时间轮算法实现(timer ...
- 3种方法判断手机浏览器跳转WAP手机网站
随着移动设备的普及,企业的网络宣传已经不能局限在PC端,而需要同时在移动端有所建树.对于公司网站来说,以前都是做的PC端的,当然手机等移动端也可以访问,但是用户体验肯定不如完全适合的手机端来的方便.我 ...
- Adobe 官方公布的 RTMP 规范
原文: http://blog.csdn.net/defonds/article/details/17534903 RTMP 规范中文版 PDF 下载地址 译序:本文是为截至发稿时止最新 Adobe ...
- easyui 在日期不满足要求的情况下,让修改链接不可点,或者修改消失
*****略***** columns:[[ {field:'id',checkbox:true}, {field:'mDate',width:10,title:'菜单日期',align:'left' ...