题目传送门

 /*
题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击
搜索水题: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. 值得收藏的45个Python优质资源(附链接)

    REST API:使用 Python,Flask,Flask-RESTful 和 Flask-SQLAlchemy 构建专业的 REST API https://www.udemy.com/rest- ...

  2. java中InputStream String

    Java 中获取输入流时,有时候须要将输入流转成String,以便获取当中的内容 ,以下总结一下 InputStream 转成String 的方式  方法1: public String conver ...

  3. CarbonData

    CarbonData http://carbondata.apache.org/ Apache顶级项目CarbonData应用实践与2.0新技术规划介绍_搜狐科技_搜狐网 https://www.so ...

  4. Git 和 SVN 之间的五个基本区别

    GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果你是一个具有使用SVN背景的人,你需要做一定的思想转换,来适应GIT提供的一些概念和特征.所以,这篇文章的主要目的就是 ...

  5. MRP 流程

    正常流程是这样的:需要>MRP>PLANNED ORDER>PR>PO PLANNED ORDER>PR>PO之间的转换可手工或自动设置转换的时间点是根据计划边际, ...

  6. (25) java web的struts2框架的使用-基于表单的文件上传

    一,首先创建一个表单页面 <body> <form action="uploads" method="post" enctype=" ...

  7. golang基础-WaitGroup、kafka消费者

    kafka消费者 以下博客是通过生产者创建.发送消息至kafka 博客链接 现在我们站在消费者的角度,来进行收取消息 package main import ( "fmt" &qu ...

  8. NEU 1685: All Pair Shortest Path

    题目描述 Bobo has a directed graph G with n vertex labeled by 1,2,3,..n. Let D(i,j) be the number of edg ...

  9. Vue中 key keep-alive

    keep-alive key <!DOCTYPE html> <html> <head> <title></title> <scrip ...

  10. POJ3268 Silver Cow Party —— 最短路

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...