ural 1152. False Mirrors
1152. False Mirrors
Memory limit: 64 MB
Background
Problem
Input
Output
Sample
| input | output |
|---|---|
7 |
9 |
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = ;
int n, Arr[N];
int Dp[<<N];
bool Visit[<<N]; inline void Input() {
scanf("%d", &n);
Rep(i, n) scanf("%d", &Arr[i]);
} inline int Calc(int State) {
static int Cal[<<N];
if(Cal[State]) return Cal[State];
int Ret = ;
Rep(i, n)
if((<<i)&State) Ret += Arr[i];
return Cal[State] = Ret;
} inline int Search(int State) {
if(Visit[State]) return Dp[State];
Visit[State] = ;
if(!State) return Dp[State] = ;
int Ret = INF;
Rep(i, n)
if((<<i)&State) {
int _State = State, _j;
For(j, i-, i+) {
_j = (j+n)%n;
if(_State&(<<_j)) _State ^= (<<_j);
}
Ret = min(Ret, Search(_State)+Calc(_State));
}
return Dp[State] = Ret;
} inline void Solve() {
int Ans = Search((<<n)-);
printf("%d\n", Ans);
} int main() {
#ifndef ONLINE_JUDGE
SetIO("C");
#endif
Input();
Solve();
return ;
}
ural 1152. False Mirrors的更多相关文章
- DFS水题 URAL 1152 False Mirrors
题目传送门 /* 题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击 搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝吧 回溯写挫 ...
- 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> ...
- URAL DP第一发
列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...
- URAL(DP集)
这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...
- DP/最短路 URAL 1741 Communication Fiend
题目传送门 /* 题意:程序从1到n版本升级,正版+正版->正版,正版+盗版->盗版,盗版+盗版->盗版 正版+破解版->正版,盗版+破解版->盗版 DP:每种情况考虑一 ...
- 回文串+回溯法 URAL 1635 Mnemonics and Palindromes
题目传送门 /* 题意:给出一个长为n的仅由小写英文字母组成的字符串,求它的回文串划分的元素的最小个数,并按顺序输出此划分方案 回文串+回溯:dp[i] 表示前i+1个字符(从0开始)最少需要划分的数 ...
- ural 1109,NYOJ 239,匈牙利算法邻接表
NYOJ 239:http://acm.nyist.net/JudgeOnline/problem.php?pid=239 ural 1109 :http://acm.timus.ru/problem ...
随机推荐
- Poj 1061 青蛙的约会(扩展GCD)
题目链接:http://poj.org/problem?id=1061 解题报告:两只青蛙在地球的同一条纬度线上,选取一个点位坐标轴原点,所以现在他们都在同一个首尾相连的坐标轴上,那么他们现在的位置分 ...
- PHP网页数据正则采集
$url ="https://********"; $contents = file_get_contents($url); //抓取页面数据 //如果出现中文乱码使用下面代码 / ...
- editorial-render A
PROBLEM LINK: PracticeContest Author: adminTester: Kevin AtienzaEditorialist: Ajay K. VermaRussian T ...
- OI 中的 FFT
不行啊最近备考简直变成文化狗了= =..我还脑洞大开想学俄语什么心态.. 简单地说一下FFT(来,跟我一起念,法〰法〜塔,法斯特~福铝页~圈死佛而母).. FFT本来是做信号变换用的,当然OI和信号变 ...
- 【云计算】Kubernetes、Marathon等框架需要解决什么样的问题?
闲谈Kubernetes 的主要特性和经验分享 Capitalonline全球云主机.全球私有网络,免费试用进行时 » 主要介绍 Kubernetes 的主要特性和一些经验.先从整体上 ...
- Java RMI 框架
RMI(即Remote Method Invoke 远程方法调用).在Java中,只要一个类extends了java.rmi.Remote接口,即可成为存在于服务器端的远程对象,供客户端访问并提供一定 ...
- HDU4870 Rating(概率)
第一场多校,感觉自己都跳去看坑自己的题目里去了,很多自己可能会比较擅长一点的题目没看,然后写一下其中一道概率题的题解吧,感觉和自己前几天做的概率dp的思路是一样的.下面先来看题意:一个人有两个TC的账 ...
- 桐桐的贸易--WA
问题 A: 桐桐的贸易 时间限制: 1 Sec 内存限制: 64 MB提交: 15 解决: 2[提交][状态][讨论版] 题目描述 桐桐家在Allianceance城,好友ROBIN家在Horde ...
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the W ...
- CodeForces - 420A (字符对称问题)
Start Up Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Sta ...