题目传送门

 /*
题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击
搜索水题: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的更多相关文章

  1. ural 1152. False Mirrors

    1152. False Mirrors Time limit: 2.0 secondMemory limit: 64 MB Background We wandered in the labyrint ...

  2. Ural 1152 False Mirrors(状压DP)

    题目地址:space=1&num=1152">Ural 1152 初学状压DP,原来状压仅仅是用到了个位运算.. 非常水的状压DP.注意四则运算的优先级是高于位运算的..也就是 ...

  3. URAL 1152. False Mirrors (记忆化搜索 状压DP)

    题目链接 题意 : 每一颗子弹破坏了三个邻近的阳台.(第N个阳台是与第1个相邻)射击后后的生存的怪物都对主角造成伤害- 如此,直到所有的怪物被消灭,求怎样射击才能受到最少伤害. 思路 : 状压,数据不 ...

  4. URAL 1152. False Mirrors(DP)

    题目链接 理解了题意之后,就不难了..状态压缩+暴力. #include <cstring> #include <cstdio> #include <string> ...

  5. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  6. 【wikioi】1229 数字游戏(dfs+水题)

    http://wikioi.com/problem/1229/ 赤裸裸的水题啊. 一开始我认为不用用完全部的牌,以为爆搜会tle.. 可是我想多了. 将所有状态全部求出,排序后暴力判断即可. (水题有 ...

  7. 咸鱼的ACM之路:DFS水题集

    DFS的核心就是从一种状态出发,转向任意的一个可行状态,直到达到结束条件为止.(个人理解) 下面全是洛谷题,毕竟能找到测试点数据的OJ我就找到这一个....在其他OJ上直接各种玄学问题... P159 ...

  8. Tree Requests CodeForces - 570D (dfs水题)

    大意: 给定树, 每个节点有一个字母, 每次询问子树$x$内, 所有深度为$h$的结点是否能重排后构成回文. 直接暴力对每个高度建一棵线段树, 查询的时候相当于求子树内异或和, 复杂度$O((n+m) ...

  9. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

随机推荐

  1. Codeforces Round #253 (Div. 2)——Borya and Hanabi

    题目连接 题意: n表示有n个卡片.每一个卡片有一种颜色和一个数字(共五种不同的颜色和五个不同的数字). 事先知道每种卡片有几张.可是不知道详细的位置. 问须要几次提示就能够知道全部卡片的位置都在哪里 ...

  2. TreeSet实现Comparator接口的排序算法的分析

    为了方便,用lambda表达式代替comparator接口 例子如下: public static void main(String[] args) { TreeSet<Integer> ...

  3. hive impala C++ Java垃圾回收 Garbage Collection GC

    hive impala impala  推荐每个节点内存  2^7~2^8GB Impala与Hive的比较 - 文章 - 伯乐在线 http://blog.jobbole.com/43233/ &l ...

  4. MapReduce ChainMapper/ChainReducer

    The ChainMapper class allows to use multiple Mapper classes within a single Map task.  The ChainRedu ...

  5. CSS中的那点事儿(一)--- CSS中的单位2

    在上篇博客提到了%.px.em三个单位,其中最复杂的是em,因为要计算当前元素内的font-size,必须知道其父元素的font-size,层层累积,容易出错.现在CSS3中引入了新的单位rem,改变 ...

  6. monitor.sh java脚本学习

    #! /bin/bash# unset any variable which system may be using# clear the screen while getopts ivh named ...

  7. Fabric原理剖析

    Fabric架构   image.png Fabric网络   image.png Fabric模块   image.png Fabric交易流 根据Hyperledger Fabric 1.0架构, ...

  8. [Selenium] Android HTML5 中 Application Cache

    HTML5 中引入了 Application Cache,这意味着 Web 应用程序可以被缓存到本地,且可在没有网络的情况下也能访问该 Web 应用程序 Application Cache 在以下3个 ...

  9. Top的VIRT是什么

    Top命令监控某个进程的资源占有情况  下面是各种内存: VIRT:virtual memory usage 1.进程“需要的”虚拟内存大小,包括进程使用的库.代码.数据等     2.假如进程申请1 ...

  10. bzoj 1657 Mooo 奶牛的歌声 —— 单调栈

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1657 单调栈水题. 代码如下: #include<iostream> #incl ...