博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Special Fish
阅读量:6802 次
发布时间:2019-06-26

本文共 3097 字,大约阅读时间需要 10 分钟。

Special Fish

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14 Accepted Submission(s): 9
 
Problem Description
There is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It’s hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of some other fish who is believed to be female by it.
A fish will spawn after it has been attacked. Each fish can attack one other fish and can only be attacked once. No matter a fish is attacked or not, it can still try to attack another fish which is believed to be female by it.
There is a value we assigned to each fish and the spawns that two fish spawned also have a value which can be calculated by XOR operator through the value of its parents.
We want to know the maximum possibility of the sum of the spawns.
 
Input
The input consists of multiply test cases. The first line of each test case contains an integer n (0 < n <= 100), which is the number of the fish. The next line consists of n integers, indicating the value (0 < value <= 100) of each fish. The next n lines, each line contains n integers, represent a 01 matrix. The i-th fish believes the j-th fish is female if and only if the value in row i and column j if 1.
The last test case is followed by a zero, which means the end of the input.
 
Output
Output the value for each test in a single line.
 
Sample Input
31 2 30111011100
 
Sample Output
6
 
Author
momodi@whu
 
Source
The 5th Guangting Cup Central China Invitational Programming Contest
 
Recommend
notonlysuccess
 
/*题意:有n条鱼,每条鱼最多只能攻击一次,被攻击一次,一次攻击产生的价值是val[i]^val[j],现在问你在满足条件的情况下能获得的最大价值    是多少。#初步思路:简化成最小割最大团问题,将0点设置成源点,tol+1设置成汇点,可以想到将一个点拆成两个点,i和i+n分别表示攻击边和被攻击边    然后跑一下#感悟:刚换了乌版图系统用的调了几天,终于正常的写代码哈哈哈。*/#include
using namespace std;int val[110];//用来存储每个鱼的价值int n;char mapn[110][110];//用来存储攻击关系int tol=0;//要是总的可能的点数/****************************************最小割最大流模板****************************************/#define INF 1e9using namespace std;const int maxn=200+10;struct Edge{ int from,to,cap,flow,cost; Edge(){} Edge(int f,int t,int c,int fl,int co):from(f),to(t),cap(c),flow(fl),cost(co){}};struct MCMF{ int n,m,s,t; vector
edges; vector
G[maxn]; bool inq[maxn]; int d[maxn]; int p[maxn]; int a[maxn]; void init(int n,int s,int t) { this->n=n, this->s=s, this->t=t; edges.clear(); for(int i=0;i
Q; Q.push(s); while(!Q.empty()) { int u=Q.front(); Q.pop(); inq[u]=false; for(int i=0;i
e.flow && d[e.to]>d[u]+e.cost) { d[e.to]= d[u]+e.cost; p[e.to]=G[u][i]; a[e.to]= min(a[u],e.cap-e.flow); if(!inq[e.to]){ Q.push(e.to); inq[e.to]=true; } } } } if(d[t]==INF) return false; flow +=a[t]; cost +=a[t]*d[t]; int u=t; while(u!=s) { edges[p[u]].flow += a[t]; edges[p[u]^1].flow -=a[t]; u = edges[p[u]].from; } return true; } int Min_cost() { int flow=0,cost=0; while(BellmanFord(flow,cost)); //cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6502985.html

你可能感兴趣的文章
TFS2008安装图解(详细版本)
查看>>
王家林每日大数据语录Spark篇0016(2015.11.6于南宁)
查看>>
android HOME点击事件的获取
查看>>
2.23——2.25find命令(上中下);2.26 文件名后缀
查看>>
华为服务器的中国梦-当梦想照进现实
查看>>
源码编译安装:隐藏nginx的版本信息
查看>>
python爬虫的常见方式
查看>>
MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践
查看>>
Linux内核源代码分析-第二章 代码初识-1
查看>>
yslow V2 准则详细讲解
查看>>
沈南鹏:从五大物理定律看新商业法则
查看>>
python学习
查看>>
TCP序列号/确认号详解
查看>>
Linux 链接详解----静态链接实例分析
查看>>
Centos7快速部署CloudStack服务器
查看>>
搭建app自动化测试环境(一)
查看>>
...
查看>>
PPII打不开 更改I.bat
查看>>
开始学习了
查看>>
Javascript 控制 让输入框不能输入 数字
查看>>