SDUT 2860-生日Party(BFS)
生日Party
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描写叙述
输入
输出
演示样例输入
4
2
1 2
0 -2
-2 0
3
-1 -1 0
0 1 1
1 0 1
1 1 0
3
1 1 1
0 -1 -1
-1 0 -1
-1 -1 0
3
-1 -1 -1
0 -2 -2
-2 0 -2
-2 -2 0
演示样例输出
2
1
1
0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef struct node
{
int a[20],ans,x,top;//a数组里面放參加party的朋友的编号
};
int ma[20][20];
int fri[20],Max,n;
void bfs()
{
node t,v;
queue <node> Q;
t.top=0;t.ans=0;t.x=-1;
Q.push(t);
while(!Q.empty())
{
v=Q.front();Q.pop();
if(v.x==n-1)//每选完一轮更新一下最大值
{
if(Max<v.ans)
Max=v.ans;
continue;
}
//两个搜索方向,要么选此人,要么不选
t.x=v.x+1;//不选第i个人
t.ans=v.ans;
t.top=v.top;
for(int i=0;i<v.top;i++)
t.a[i]=v.a[i];
Q.push(t);//选第i个人
t.top=v.top+1;
t.a[v.top]=t.x;
t.ans=v.ans+fri[t.x];
for(int i=0;i<v.top;i++)
t.ans+=ma[t.a[i]][t.x];
Q.push(t);
}
}
int main()
{
int T,i,j;
cin>>T;
while(T--)
{
cin>>n;
for(i=0;i<n;i++)
cin>>fri[i];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>ma[i][j];
Max=-1;
bfs();
if(Max<0)
cout<<"0"<<endl;
else
cout<<Max<<endl; }
return 0;
}
SDUT 2860-生日Party(BFS)的更多相关文章
- SDUT OJ 图练习-BFS-从起点到目标点的最短步数 (vector二维数组模拟邻接表+bfs , *【模板】 )
图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 在古老的魔兽传说中,有两个军团,一个叫天 ...
- SDUT 1269 走迷宫(BFS)
点我看题目 题意:中文不详述. 思路 :上上上场比赛让一个BFS给虐了,上次比赛让一个三维的给废掉了.......所以急于从水题刷起......还因为数组开小了WA了5,6次 #include < ...
- SDUT 1124-飞跃荒野(三维BFS)
飞跃原野 Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 勇敢的法里奥出色的完毕了任务之后.正在迅速地向自己的基地撤退.但因为 ...
- SDUT 1157-小鼠迷宫问题(BFS&DFS)
小鼠迷宫问题 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit1500ms Memory Limit 65536 ...
- SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...
- sdut oj 3058 路线冲突问题(BFS+记录路径算法,回溯路径 )
路线冲突问题 题目描述 给出一张地图,地图上有n个点,任意两点之间有且仅有一条路.点的编号从1到n. 现在兵团A要从s1到e1,兵团B要从s2到e2,问两条路线是否会有交点,若有则输出交点个数,否出输 ...
- SDUT OJ 1124 飞越原野 (三维BFS练习)
飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...
- 基于邻接矩阵的广度优先搜索遍历(BFS)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...
- 基于邻接表的广度优先搜索遍历(bfs)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2142&cid=1186 #include<stdio.h> #incl ...
随机推荐
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )
裸的LIS ----------------------------------------------------------------- #include<cstdio> #incl ...
- C# Programming Study #1
引用的时候需要在参数和使用的时候加上 ref 关键字 static bool addnum (ref int val) //引用 { ++val; return true; } 参数数组的概念,可以接 ...
- LinuxC安装gcc
使用centos进行C编程的时候使用gcc hello.c提示 bash:gcc:command not found 此时需要给Linux安装gcc命令如下 1 yum -y install gcc ...
- 一个ShellExecute的超全说明(www.phidels.com这个网站很多内容)
I. Introduction / Déclaration ShellExecute fait partie des innombrables fonctions de l'API Windows ; ...
- nginx自动切割访问日志
Web 访问日志 (access_log) 记录了所有外部客户端对Web服务器的访问行为,包含了客户端IP,访问日期,访问的URL资源,服务器返回的HTTP状态码等重要信息. 一条典型的Web访问日志 ...
- 引用 字库编码Unicode相关知识
引用 weifeng.shen 的 字库编码Unicode相关知识 1. 各地编码 首先说明一下现在常用的一些编码方案: 1. 在中国,大陆最常用的就是GBK18030编码, ...
- How many integers can you find(容斥+dfs容斥)
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- jsp小商城
一个小商城,当然,没淘宝那么厉害,只是那时学完j2ee后,发现java原来也可以做网站,学了数据库,servlet,jsp,当时是很惊喜的,可以直接做个这样的东西.而放到今天,学了更多之后,发现可以用 ...
- 【Android】ScrollView+GridView 显示问题
在使用Android的ScrollView里面嵌套GridView时,设置android:layout_height="wrap_content"属性,运行界面的效果不会出现全部数 ...
- BZOJ 3408: [Usaco2009 Oct]Heat Wave 热浪( 最短路 )
普通的最短路...dijkstra水过.. ------------------------------------------------------------------------------ ...