hdu4536-XCOM Enemy Unknown(爆搜)


[Technical Specification] 0<T<=100 8<n<=16 2<m<=5 0<k<=100 0<初始恐慌值<=5 每个州至少有三个国家 每次外星人进攻一定发生在不同州的三个国家
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
const int INF=1e9+;
const double eps=1e-;
const int maxn=;
int N,M,K;
vector<int> G[maxn];
int bel[maxn],val[maxn],ans;
struct Atk
{
int x,y,z;
Atk(int x=,int y=,int z=):x(x),y(y),z(z){}
}atk[];
bool work(int a,int y)
{
for(int i=;i<G[a].size();i++)
{
int c=G[a][i];
if(c==y) val[c]+=;
else val[c]+=;
if(val[c]>) return false;
}
return true;
}
void dfs(int step)
{
ans=max(ans,step);
if(step>=K) return;
int B[maxn];
for(int i=;i<N;i++) B[i]=val[i];
Atk& t=atk[step];
int x=t.x,y=t.y,z=t.z;
val[x]-=;
if(val[x]<) val[x]=;
if(work(bel[y],y)&&work(bel[z],z)) dfs(step+);
for(int i=;i<N;i++) val[i]=B[i];
val[y]-=;
if(val[y]<) val[y]=;
if(work(bel[x],x)&&work(bel[z],z)) dfs(step+);
for(int i=;i<N;i++) val[i]=B[i];
val[z]-=;
if(val[z]<) val[z]=;
if(work(bel[x],x)&&work(bel[y],y)) dfs(step+);
for(int i=;i<N;i++) val[i]=B[i];
return;
}
int main()
{
int T,Case=;
scanf("%d",&T);
while(T--)
{
for(int i=;i<maxn;i++) G[i].clear();
scanf("%d%d%d",&N,&M,&K);
int x,y,z;
for(int i=;i<N;i++)
{
scanf("%d",&x);
bel[i]=x;
G[x].push_back(i);
}
for(int i=;i<N;i++) scanf("%d",&val[i]);
for(int i=;i<K;i++)
{
scanf("%d%d%d",&x,&y,&z);
atk[i]=Atk(x,y,z);
}
ans=;
dfs();
printf("Case #%d: %d\n",++Case,ans);
}
return ;
}
hdu4536-XCOM Enemy Unknown(爆搜)的更多相关文章
- HDU4536 XCOM Enemy Unknown(dfs)
题目链接. 分析: 用dfs枚举每一波攻击的三个国家. 很暴力,但没想到0ms. #include <iostream> #include <cstdio> #include ...
- 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1817 Solved: 665[Submit][Status] ...
- POJ 1166 The Clocks (爆搜 || 高斯消元)
题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...
- 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)
Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...
- hdu5323 Solve this interesting problem(爆搜)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Solve this interesting problem Time Limit ...
- poj1077 Eight【爆搜+Hash(脸题-_-b)】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
- [NOIP2015] 斗地主 大爆搜
考试的时候想了半天,实在是想不到解决的办法,感觉只能暴力..然后暴力也懒得打了,小数据模拟骗30分hhh 然而正解真的是暴力..大爆搜.. 然后我的内心拒绝改这道题(TAT) 不过在wcx大佬的帮助下 ...
- BZOJ 1207: [HNOI2004]打鼹鼠【妥妥的n^2爆搜,dp】
1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3259 Solved: 1564[Submit][Statu ...
- HDU 4403 A very hard Aoshu problem(dfs爆搜)
http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...
随机推荐
- testng跑失败用例重试
testng 提高用例通过率,失败用例要重新运行一次 步骤: 1.新建一个Retry 类,implements IRetryAnalyzer接口,这个类里面确定重跑次数,以及分析每次失败是否需要重新运 ...
- 站点建设10个最好的响应的HTML5滑块插件
大多数的最佳响应的HTML5滑块插件能够使用移动应用程序,站点建设项目,以及Web开发项目提供一些令人兴奋的功能,如无限的动画效果,百分之中的一个百响应布局设计和很多其它. 1.别急!慢慢来 功能丰富 ...
- 实战ffs函数
这个函数是返回整形的最低位1的位置 自己写是这个样子的: /* Find the first bit set in I. */ int lx_ffs(int i) { int index = 0, r ...
- Android万能分辨率适应法
(1)获取屏幕的尺寸 WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); D ...
- idmap_ad — Samba's idmap_ad Backend for Winbind《转载》
Name idmap_ad — Samba's idmap_ad Backend for Winbind DESCRIPTION The idmap_ad plugin provides a way ...
- javascript什么是函数
函数是完成某个特定功能的一组词语.如没有函数,完成任务可能需要五行.十行.甚至更多的代码. 这是未满就可以把完成特定功能的代码块放到一个函数里,直接调用这个函数,就省重复输入大量代码的麻烦. 如何定义 ...
- (转)sql语句中charindex的用法
假如你写过很多程序,你可能偶尔会碰到要确定字符或字符窜串否包含在一段文字中,在这篇文章中,我将讨论使用CHARINDEX和PATINDEX函数来搜索文字列和字符串.我将告诉你这两个函数是如何运转的,解 ...
- NSDictionary使用小结
http://blog.csdn.net/ms2146/article/details/8656787
- Qt添加窗口背景图片、Label图片显示、、Label文字显示
一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...
- VC++函数(win32_exe)
1.windows输出,以对话框的方式. int MessageBox( HWND hWnd, // handle to owner window LPCTSTR lpText, // text in ...